-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRobotanSetup.ino
More file actions
133 lines (105 loc) · 4.32 KB
/
Copy pathRobotanSetup.ino
File metadata and controls
133 lines (105 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
To upload through terminal you can use: curl -u Robotan:Robotan88 -F "image=@fRobotan.ino.bin" robotan.local:8080/update
Adjust credentials in case you changed them from default.
*/
/*
By default this script will become an AP and spawn a new WLAN network.
The default network name is "Robotan" and the WiFi password is "Robotan88" (without quotation marks).
If you provide your WLAN local network SSID / password information, the script will first try to connect to your
existing local WLAN network as a client. Upon success, local WLAN credentials will be stored in the EEPROM and the robotan
firmware will connect after flashed and restarted.Only if the local WLAN connection is unsuccessful, the script will revert to default behavior
If you decide to change the default username / password (recommended), the new values will be copied to the Wemos EEPROM
and be active after the robotan firmware file has been flashed and restarted.
Thanks to Oliver Weismantel for helpful additions!
*/
#define LOGIN_CREDENTIALS_LENGTH_MAX 16
/* begin configuration section */
const char WLAN_local_SSID[32] = ""; // fill in your existing local WLAN SSID
const char WLAN_local_password[63] =""; // fill infor your existing local WLAN password
const char http_username[LOGIN_CREDENTIALS_LENGTH_MAX + 1] = "Robotan"; // HTTP username, maximum of 16 characters
const char http_password[LOGIN_CREDENTIALS_LENGTH_MAX + 1] = "Robotan88"; // HTTP password, maximum of 16 characters
/* end configuration section */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <EEPROM.h>
extern "C" {
#include "user_interface.h"
}
const char* host = "robotan";
const char* def_ssid = "Robotan";
const char* def_pass = "Robotan88";
int eeprom_allocated_mem = 4096;
int eeprom_login_credentials_base=512;
ESP8266WebServer httpServer(8080);
ESP8266HTTPUpdateServer httpUpdater;
WiFiClient WLAN_Client;
IPAddress local_ip;
void setup(void) {
/* Initialize Serial Port */
Serial.begin(38400);
Serial.println();
/* Clear EEPROM */
Serial.print("Clearing EEPROM...");
EEPROM.begin(eeprom_allocated_mem);
for (int i = 0; i < eeprom_allocated_mem; ++i) {
EEPROM.write(i, 0);
}
Serial.println("done");
/* Store http username / password in EEPROM */
EEPROM.put(eeprom_login_credentials_base, http_username);
EEPROM.put(eeprom_login_credentials_base + LOGIN_CREDENTIALS_LENGTH_MAX, http_password);
Serial.println("Setting up Firmware Upload Tool...");
if (!Local_WLAN_Connect()) {
/* default behavior - spawn access point */
WiFi.mode(WIFI_AP);
wifi_station_set_hostname((char*)"robotan");
WiFi.softAP(def_ssid, def_pass);
Serial.printf("Created WLAN access point with WLAN SSID %s\n",def_ssid);
/* local IP */
local_ip = WiFi.softAPIP();
Serial.printf("\n>>> Connect to WiFi network \"%s\" with password \"%s\"\n\n",def_ssid, def_pass);
}
EEPROM.commit();
EEPROM.end();
/* Start Update Server Process */
httpUpdater.setup(&httpServer);
httpServer.begin();
/* Ready */
Serial.printf("\n>>> HTTPUpdateServer ready!\n>>> Open http://");
Serial.print(local_ip);
Serial.print(":8080/update in your browser to upload the Robotan firmware.\n");
return;
}
void loop(void){
httpServer.handleClient();
}
boolean Local_WLAN_Connect() {
/* Try local WLAN using credentials given */
if ( strlen(WLAN_local_SSID) && strlen(WLAN_local_password)) {
/* Wifi client mode */
WiFi.mode(WIFI_STA);
/* connect to existing WLAN */
Serial.printf("Connecting to local WLAN SSID %s",WLAN_local_SSID);
WiFi.begin(WLAN_local_SSID, WLAN_local_password);
/* Wait for connection to be successful */
for (int i=0; i<20; i++) { //timeout [s]
delay(1000);
int connectionStatus = WiFi.status();
switch(connectionStatus) {
case WL_CONNECTED:
Serial.println("...connected");
local_ip = WiFi.localIP();
/* store WiFi credentials in EEPROM */
EEPROM.put(0,WLAN_local_SSID);
EEPROM.put(32,WLAN_local_password);
return true; // WLAN connection successful
default:
Serial.print(".");
}
}
}
Serial.println("...unable to connect"); // revert to default behavior
return false;
}