Hi I did the Esp8266 internet connected switch but i am trying to add more relays and sensors.
I cannot not even change the pin out of tje code. I am trying to have the board to send a signal on pin5 instead 2 as the code and it doesn't work. It still sending signal from pin2 not matter what I write on outPin.
Also i need to add sensors and more relays on the app part of it as well.
I am usinh Nodemcu board v12.
Please help me.
Thanks
Below is the code
As you can see I have changed the ( const int outPin = 5; /////////////////////////////////////////////////////////////////////////////////2) to io5 but it has not changed anything. is still turning on the LED and sending signal to io2.
struct StoreStruct {
// This is for mere detection if they are your settings
char version[4];
// The variables of your settings
uint moduleId; // module id
bool state; // state
char ssid[20];
char pwd[20];
} storage = {
CONFIG_VERSION,
// The default module 0
0,
0, // off
AP_SSID,
AP_PASSWORD
};
Serial.println("Connecting to MQTT server");
#endif
//set client id
// Generate client name based on MAC address and last 8 bits of microsecond counter
String clientName;
uint8_t mac[6];
WiFi.macAddress(mac);
clientName += macToStr(mac);
clientName += "-";
clientName += String(micros() & 0xff, 16);
myMqtt.setClientId((char*) clientName.c_str());
String macToStr(const uint8_t* mac)
{
String result;
for (int i = 0; i < 6; ++i) {
result += String(mac, 16);
if (i < 5)
result += ':';
}
return result;
}
void loadConfig() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (EEPROM.read(CONFIG_START + 0) == CONFIG_VERSION[0] &&
EEPROM.read(CONFIG_START + 1) == CONFIG_VERSION[1] &&
EEPROM.read(CONFIG_START + 2) == CONFIG_VERSION[2])
for (unsigned int t=0; t<sizeof(storage); t++)
*((char*)&storage + t) = EEPROM.read(CONFIG_START + t);
}
void saveConfig() {
for (unsigned int t=0; t<sizeof(storage); t++)
EEPROM.write(CONFIG_START + t, *((char*)&storage + t));
bool inf_loop = true;
int val = 0;
WiFiClient client;
Serial.println("AP loop");
while(inf_loop){
while (!client){
Serial.print(".");
delay(100);
client = server.available();
}
String ssid;
String passwd;
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
// Prepare the response. Start with the common header:
String s = "HTTP/1.1 200 OK\r\n";
s += "Content-Type: text/html\r\n\r\n";
s += "<!DOCTYPE HTML>\r\n<html>\r\n";
if (req.indexOf("&") != -1){
int ptr1 = req.indexOf("ssid=", 0);
int ptr2 = req.indexOf("&", ptr1);
int ptr3 = req.indexOf(" HTTP/",ptr2);
ssid = req.substring(ptr1+5, ptr2);
passwd = req.substring(ptr2+10, ptr3);
val = -1;
}
if (val == -1){
strcpy(storage.ssid, ssid.c_str());
strcpy(storage.pwd, passwd.c_str());
saveConfig();
//storeAPinfo(ssid, passwd);
s += "Setting OK";
s += "<br>"; // Go to the next line.
s += "Continue / reboot";
inf_loop = false;
}
else{
String content="";
// output the value of each analog input pin
content += "<form method=get>";
content += "<label>SSID</label><br>";
content += "<input type='text' name='ssid' maxlength='19' size='15' value='"+ String(storage.ssid) +"'><br>";
content += "<label>Password</label><br>";
content += "<input type='password' name='password' maxlength='19' size='15' value='"+ String(storage.pwd) +"'><br><br>";
content += "<input type='submit' value='Submit' >";
content += "</form>";
s += content;
}
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
client.stop();
}
}