my project is a bedside clock that gets time and weather via the web. i have a nano and an ESP8266 module on hand and once i seal my clock up i wouldn’t want to have to take it apart again once i moved. i’m trying to store ssid,password,city,and country code on the ESP but if in the future where to program new credentials in it i wanted to use the nano as a proxy. i’m stuck on Strings and structs. i can get the values to input via Serial but there’s something going on in the saving and recovery of strings. i’ve tried to isolate this as much as possible, putting the essential code in its own sketch and plugging the serial monitor directly into the ESP. no error codes during compiling.
-Thanks
the code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>
struct myObject{
String feild1;
String feild2;
String feild3;
String feild4;
};
String ssid = "";
String pass = "";
String city = "";
String country = "";
int actionCode = 0;
void setup() {
Serial.begin(9600);
while(!Serial.available()){}
actionCode = Serial.parseInt();
if(actionCode == 100){
Serial.println();
delay(1000);
while(Serial. read() >= 0) ;
Serial.print("SSID: ");
while(!Serial.available()){}
ssid = Serial.readString();
Serial.println(ssid);
Serial.print("Password: ");
while(!Serial.available()){}
pass = Serial.readString();
Serial.println(pass);
Serial.print("City: ");
while(!Serial.available()){}
city = Serial.readString();
Serial.println(city);
Serial.print("Contry code: ");
while(!Serial.available()){}
country = Serial.readString();
Serial.println(country);
myObject wifiStuff = {
ssid,
pass,
city,
country
};
EEPROM.put(0, wifiStuff);
}
myObject wifiStuffRetrieve;
EEPROM.get(0, wifiStuffRetrieve);
ssid = wifiStuffRetrieve.feild1;
pass = wifiStuffRetrieve.feild2;
city = wifiStuffRetrieve.feild3;
country = wifiStuffRetrieve.feild4;
Serial.print("ssid: ");
Serial.println(ssid);
Serial.print("password: ");
Serial.println(pass);
Serial.print("city: ");
Serial.println(city);
Serial.print("country: ");
Serial.println(country);
Serial.println("");
WiFi.begin(ssid,pass);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi Connected");
printWiFiStatus();
Serial.print("xxCONECTEDxx");
}
void loop(){
int actionCode = Serial.parseInt();
if(actionCode == 100 || actionCode == 200){
Serial.print("xxCONECTEDxx");
}
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
the monitor
4⸮!⸮⸮⸮⸮OAqr⸮⸮ //<<<< garbage from restarting the ESP8266
SSID: funny //<<<< these are prompts like "SSID" then wait,
// the "funny" was the example which was echoed
Password: stuff
City: liberty
Country code: us
ssid: //<<<<< these should be populated by the inputs above
password:
city:
country:
connectingWiFi Connected
SSID: "the ssid that shows here is old and this does not change with new entries"
IP Address: 192.168.0.28
signal strength (RSSI):-55 dBm
xxCONECTEDxx