Hello everyone,
I am trying to connect wifi to my ESP8266 wifi module to control my ARDUINO but every time . It gets connected for just a few seconds and gets failed.I tried but could not find any way to connect.
Can someone help me with this problem?
Here is the error that i receive through serial monitor
13:15:35.985 -> timeout 2
13:15:35.985 -> ESP CWMODE SET FAILED
13:15:40.967 -> ESP SSID SET OK
13:15:40.967 -> CHECKING FOR AN IP ADDRESS
13:15:41.001 -> IP ADDRESS = +CICSR:STAMAC,"0p:fe:34:a5:8`:4b"
13:15:45.979 -> timeout 2
13:15:45.979 -> ESP CIPMUX SET FAILED
13:15:47.005 -> CONNECTING
13:15:47.999 -> CONNECTED
13:15:48.032 -> READY TO SEND
13:15:48.032 -> 109
13:15:48.032 -> GET /TX.php?id=99999&pw=12345&un=1&n1=401 HTTP/1.1
13:15:48.032 -> Host: homiecube.000webhostapp.com/
13:15:48.032 -> Connection: close
**13:15:48.065 -> **
13:15:53.039 -> timeout 2
13:15:53.039 -> FAILED TO SEND
13:15:58.047 -> timeout 1
13:15:59.075 -> CONNECTING
13:15:59.606 -> CONNECTED
13:16:04.615 -> timeout 2
13:16:04.615 -> FAILED TO GET >
13:16:09.595 -> timeout 2
13:16:10.623 -> CONNECTING
13:16:15.598 -> timeout 2
13:16:15.598 -> FAILED TO CONNECT
My code is bit long
code:-
//Include the needed library, we will use softer serial communication with the ESP8266
#include <SoftwareSerial.h>
#include <avr/power.h>
//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //sometimes the LCD adress is not 0x3f. Change to 0x27 if it dosn't work.
//Define the used
#define ESP8266_RX 10 //Connect the TX pin from the ESP to this RX pin of the Arduino
#define ESP8266_TX 11 //Connect the TX pin from the Arduino to the RX pin of ESP
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int Potentiometer_1 = A0;
int Potentiometer_2 = A1;
int Potentiometer_3 = A2;
int Potentiometer_4 = A3;
int switch1 = 7;
int switch2 = 8;
int switch3 = 9;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Variables you must change according to your values/////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add your data: SSID + KEY + host + location + id + password
//////////////////////////////////////////////
const char SSID_ESP[] ="udit"; //Give EXACT name of your WIFI
const char SSID_KEY[] ="password"; //Add the password of that WIFI connection
const char* host ="homiecube.000webhostapp.com/"; //Add the host without "www" Example: electronoobs.com
String NOOBIX_id ="99999"; //This is the ID you have on your database, I've used 99999 becuase there is a maximum of 5 characters
String NOOBIX_password = "12345"; //Add the password from the database, also maximum 5 characters and only numerical values
String location_url = "/TX.php?id="; //location of your PHP file on the server. In this case the TX.php is directly on the first folder of the server
//If you have the files in a different folder, add thas as well, Example: "/ESP/TX.php?id=" Where the folder is ESP
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Used variables in the code
String url = "";
String URL_withPacket = "";
unsigned long multiplier[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
//MODES for the ESP
const char CWMODE = '1';//CWMODE 1=STATION, 2=APMODE, 3=BOTH
const char CIPMUX = '1';//CWMODE 0=Single Connection, 1=Multiple Connections
//Define the used functions later in the code, thanks to Kevin Darrah, YT channel: https://www.youtube.com/user/kdarrah1234
boolean setup_ESP();
boolean read_until_ESP(const char keyword1[], int key_size, int timeout_val, byte mode);
void timeout_start();
boolean timeout_check(int timeout_ms);
void serial_dump_ESP();
boolean connect_ESP();
void connect_webhost();
unsigned long timeout_start_val;
char scratch_data_from_ESP[20];//first byte is the length of bytes
char payload[200];
byte payload_size = 0, counter = 0;
char ip_address[16];
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Variable to SEND to the DATABASE
bool sent_bool_1 = 0;
bool sent_bool_2 = 0;
bool sent_bool_3 = 0;
int sent_nr_1 = 0;
int sent_nr_2 = 0;
int sent_nr_3 = 0;
int sent_nr_4 = 0;
int sent_nr_5 = 0;
//Variable RECEIVED from the DATABASE
bool received_bool_1 = 0;
bool received_bool_2 = 0;
bool received_bool_3 = 0;
bool received_bool_4 = 0;
bool received_bool_5 = 0;
int received_nr_1 = 0;
int received_nr_2 = 0;
int received_nr_3 = 0;
int received_nr_4 = 0;
int received_nr_5 = 0;
String received_text = "";
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Store received chars in this variables
char t1_from_ESP[5]; //For time from web
char d1_from_ESP[2]; //For received_bool_2
char d2_from_ESP[2]; //For received_bool_2
char d3_from_ESP[2]; //For received_bool_3
char d4_from_ESP[2]; //For received_bool_4
char d5_from_ESP[2]; //For received_bool_5
char d9_from_ESP[6]; //For received_nr_1
char d10_from_ESP[6]; //For received_nr_2
char d11_from_ESP[6]; //For received_nr_3
char d12_from_ESP[6]; //For received_nr_4
char d13_from_ESP[6]; //For received_nr_5
char d14_from_ESP[300]; //For received_text
//DEFINE KEYWORDS HERE
const char keyword_OK[] = "OK";
const char keyword_Ready[] = "Ready";
const char keyword_no_change[] = "no change";
const char keyword_blank[] = "#&";
const char keyword_ip[] = "192.";
const char keyword_rn[] = "\r\n";
const char keyword_quote[] = "\"";
const char keyword_carrot[] = ">";
const char keyword_sendok[] = "SEND OK";
const char keyword_linkdisc[] = "Unlink";
const char keyword_t1[] = "t1";
const char keyword_b1[] = "b1";
const char keyword_b2[] = "b2";
const char keyword_b3[] = "b3";
const char keyword_b4[] = "b4";
const char keyword_b5[] = "b5";
const char keyword_n1[] = "n1";
const char keyword_n2[] = "n2";
const char keyword_n3[] = "n3";
const char keyword_n4[] = "n4";
const char keyword_n5[] = "n5";
const char keyword_n6[] = "n6";
const char keyword_doublehash[] = "##";
SoftwareSerial ESP8266(ESP8266_RX, ESP8266_TX);// rx tx
void setup() { // SETUP START
lcd.init(); //Init the LCD
lcd.backlight(); //Activate backlight
//Pin Modes for ESP TX/RX
pinMode(ESP8266_RX, INPUT);
pinMode(ESP8266_TX, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(Potentiometer_1, INPUT);
pinMode(Potentiometer_2, INPUT);
pinMode(Potentiometer_3, INPUT);
pinMode(Potentiometer_4, INPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
ESP8266.begin(115200);//default baudrate for ESP
ESP8266.listen();//not needed unless using other software serial instances
Serial.begin(115200); //for status and debug
delay(2000);//delay before kicking things off
setup_ESP();//go setup the ESP
}
void loop() {
sent_nr_1 = analogRead(Potentiometer_1);
sent_nr_1 = analogRead(Potentiometer_2);
sent_nr_1 = analogRead(Potentiometer_3);
sent_nr_1 = analogRead(Potentiometer_4);
sent_bool_1 = digitalRead(switch1);
sent_bool_2 = digitalRead(switch2);
sent_bool_3 = digitalRead(switch3);
send_to_server_1();
digitalWrite(LED1, received_bool_1);
digitalWrite(LED2, received_bool_2);
digitalWrite(LED3, received_bool_3);
digitalWrite(LED4, received_bool_4);
digitalWrite(LED5, received_bool_5);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0, 1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);//5 seconds between tries
/*
send_to_server_2();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
send_to_server_3();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
send_to_server_4();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
*/
send_to_server_5();
digitalWrite(LED1, received_bool_1);
digitalWrite(LED2, received_bool_2);
digitalWrite(LED3, received_bool_3);
digitalWrite(LED4, received_bool_4);
digitalWrite(LED5, received_bool_5);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(received_text);
delay(1000);
}//End of the main loop
boolean connect_ESP() { //returns 1 if successful or 0 if not
Serial.println("CONNECTING");
//or 443 para HTTPS
//enshare.000webhostapp.co
ESP8266.print("AT+CIPSTART=0,\"TCP\",\"www.homiecube.000webhostapp.com\",80\r\n");//connect to your web server
//read_until_ESP(keyword,size of the keyword,timeout in ms, data save 0-no 1-yes 'more on this later')
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) { //go look for 'OK' and come back
serial_dump_ESP();//get rid of whatever else is coming
Serial.println("CONNECTED");//yay, connected
ESP8266.print("AT+CIPSEND=0,");//send AT+CIPSEND=0, size of payload
ESP8266.print(payload_size);//the payload size
serial_dump_ESP();//everything is echoed back, so get rid of it
ESP8266.print("\r\n\r\n");//cap off that command with a carriage return and new line feed
if (read_until_ESP(keyword_carrot, sizeof(keyword_carrot), 5000, 0)) { //go wait for the '>' character, ESP ready for the payload
Serial.println("READY TO SEND");
Serial.println(payload_size);
for (int i = 0; i < payload_size; i++)
{ //print the payload to the ESP
ESP8266.print(payload[i]);
Serial.print(payload[i]);
}
/*
Serial.println("");
Serial.println(payload_size);
Serial.println("");
*/
if (read_until_ESP(keyword_sendok, sizeof(keyword_sendok), 5000, 0)) { //go wait for 'SEND OK'
Serial.println("SENT");//yay, it was sent
return 1;//get out of here, data is about to fly out of the ESP
}// got the SEND OK
else// SEND OK
Serial.println("FAILED TO SEND");
}//got the back carrot >
else
Serial.println("FAILED TO GET >");
}//First OK
else {
Serial.println("FAILED TO CONNECT");//something went wrong
setup_ESP();//optional, this will go setup the module and attempt to repair itself - connect to SSID, set the CIPMUX, etc...
}
}// VOID CONNECT FUNCTION
boolean connect_ESP() { //returns 1 if successful or 0 if not
Serial.println("CONNECTING");
//or 443 para HTTPS
//enshare.000webhostapp.co
ESP8266.print("AT+CIPSTART=0,\"TCP\",\"www.homiecube.000webhostapp.com\",80\r\n");//connect to your web server
//read_until_ESP(keyword,size of the keyword,timeout in ms, data save 0-no 1-yes 'more on this later')
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) { //go look for 'OK' and come back
serial_dump_ESP();//get rid of whatever else is coming
Serial.println("CONNECTED");//yay, connected
ESP8266.print("AT+CIPSEND=0,");//send AT+CIPSEND=0, size of payload
ESP8266.print(payload_size);//the payload size
serial_dump_ESP();//everything is echoed back, so get rid of it
ESP8266.print("\r\n\r\n");//cap off that command with a carriage return and new line feed
if (read_until_ESP(keyword_carrot, sizeof(keyword_carrot), 5000, 0)) { //go wait for the '>' character, ESP ready for the payload
Serial.println("READY TO SEND");
Serial.println(payload_size);
for (int i = 0; i < payload_size; i++)
{ //print the payload to the ESP
ESP8266.print(payload[i]);
Serial.print(payload[i]);
}
/*
Serial.println("");
Serial.println(payload_size);
Serial.println("");
*/
if (read_until_ESP(keyword_sendok, sizeof(keyword_sendok), 5000, 0)) { //go wait for 'SEND OK'
Serial.println("SENT");//yay, it was sent
return 1;//get out of here, data is about to fly out of the ESP
}// got the SEND OK
else// SEND OK
Serial.println("FAILED TO SEND");
}//got the back carrot >
else
Serial.println("FAILED TO GET >");
}//First OK
else {
Serial.println("FAILED TO CONNECT");//something went wrong
setup_ESP();//optional, this will go setup the module and attempt to repair itself - connect to SSID, set the CIPMUX, etc...
}
}// VOID CONNECT FUNCTION
void send_to_server_1() {
//we have changing variable here, so we need to first build up our URL packet
/*URL_withPacket = URL_webhost;//pull in the base URL
URL_withPacket += String(unit_id);//unit id value
URL_withPacket += "&sensor=";//unit id 1
URL_withPacket += String(sensor_value);//sensor value
URL_withPacket += payload_closer;*/
url = location_url;
url += NOOBIX_id;
url += "&pw=";
url += NOOBIX_password;//sensor value
url += "&un=1";
url += "&n1=";
url += String(sent_nr_1);//sensor value
URL_withPacket = "";
URL_withPacket = (String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
/*
URL_withPacket += "Host: www.electronoobs.com\r\n";
URL_withPacket += "Connection: close\r\n\r\n";
*/
/// This builds out the payload URL - not really needed here, but is very handy when adding different arrays to the payload
counter = 0; //keeps track of the payload size
payload_size = 0;
for (int i = 0; i < (URL_withPacket.length()); i++) { //using a string this time, so use .length()
payload[payload_size + i] = URL_withPacket[i]; //build up the payload
counter++;//increment the counter
}//for int
payload_size = counter + payload_size; //payload size is just the counter value - more on this when we need to build out the payload with more data
//for(int i=0; i<payload_size; i++)//print the payload to the ESP
//Serial.print(payload[i]);
if (connect_ESP()) { //this calls 'connect_ESP()' and expects a '1' back if successful
//nice, we're in and ready to look for data
//first up, we need to parse the returned data _t1123##_d15##_d210##
//Serial.println("connected ESP");
if (read_until_ESP(keyword_t1, sizeof(keyword_t1), 5000, 0)) { //go find t1 then stop
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //our data is next, so change mode to '1' and stop at ##
//got our data, so quickly store it away in d1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++) //go see 'setup' and how this was done with the ip address for more info
t1_from_ESP[i] = scratch_data_from_ESP[i];
t1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//we still have more data to get out of this stream, now we want d1
if (read_until_ESP(keyword_b1, sizeof(keyword_b1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d1_from_ESP[i] = scratch_data_from_ESP[i];
d1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b2, sizeof(keyword_b2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d2_from_ESP[i] = scratch_data_from_ESP[i];
d2_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b3, sizeof(keyword_b3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d3_from_ESP[i] = scratch_data_from_ESP[i];
d3_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b4, sizeof(keyword_b4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d4_from_ESP[i] = scratch_data_from_ESP[i];
d4_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b5, sizeof(keyword_b5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d5_from_ESP[i] = scratch_data_from_ESP[i];
d5_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n1, sizeof(keyword_n1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d9_from_ESP[i] = scratch_data_from_ESP[i];
d9_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n2, sizeof(keyword_n2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n3, sizeof(keyword_n3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n4, sizeof(keyword_n4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n5, sizeof(keyword_n5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d13_from_ESP[i] = scratch_data_from_ESP[i];
d13_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n6, sizeof(keyword_n6), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d14_from_ESP[i] = scratch_data_from_ESP[i];
d14_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.println("");
Serial.print("Time ");
if (t1_from_ESP[0] > 3) {
Serial.print(t1_from_ESP[1]);
Serial.print(t1_from_ESP[2]);
Serial.print(":");
Serial.print(t1_from_ESP[3]);
Serial.println(t1_from_ESP[4]);
}
else {
Serial.print(t1_from_ESP[1]);
Serial.print(":");
Serial.print(t1_from_ESP[2]);
Serial.println(t1_from_ESP[3]);
}
Serial.print("RECEIVED_BOOL_1 = ");//print out LED data and convert to integer
received_bool_1 = 0;
for (int i = 1; i <= d1_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_1 = received_bool_1 + ((d1_from_ESP[i] - 48) * multiplier[d1_from_ESP[0] - i]);
}
Serial.println(received_bool_1);
Serial.print("RECEIVED_BOOL_2 = ");//print out LED data and convert to integer
received_bool_2 = 0;
for (int i = 1; i <= d2_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_2 = received_bool_2 + ((d2_from_ESP[i] - 48) * multiplier[d2_from_ESP[0] - i]);
}
Serial.println(received_bool_2);
Serial.print("RECEIVED_BOOL_3 = ");//print out LED data and convert to integer
received_bool_3 = 0;
for (int i = 1; i <= d3_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_3 = received_bool_3 + ((d3_from_ESP[i] - 48) * multiplier[d3_from_ESP[0] - i]);
}
Serial.println(received_bool_3);
Serial.print("RECEIVED_BOOL_4 = ");//print out LED data and convert to integer
received_bool_4 = 0;
for (int i = 1; i <= d4_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_4 = received_bool_4 + ((d4_from_ESP[i] - 48) * multiplier[d4_from_ESP[0] - i]);
}
Serial.println(received_bool_4);
Serial.print("RECEIVED_BOOL_5 = ");//print out LED data and convert to integer
received_bool_5 = 0;
for (int i = 1; i <= d5_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_5 = received_bool_5 + ((d5_from_ESP[i] - 48) * multiplier[d5_from_ESP[0] - i]);
}
Serial.println(received_bool_5);
Serial.print("RECEIVED_NUMBER_1 = ");//print out LED data and convert to integer
received_nr_1 = 0;
for (int i = 1; i <= d9_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_1 = received_nr_1 + ((d9_from_ESP[i] - 48) * multiplier[d9_from_ESP[0] - i]);
}
Serial.println(received_nr_1);
Serial.print("RECEIVED_NUMBER_2 = ");//print out LED data and convert to integer
received_nr_2 = 0;
for (int i = 1; i <= d10_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_2 = received_nr_2 + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(received_nr_2);
Serial.print("RECEIVED_NUMBER_3 = ");//print out LED data and convert to integer
received_nr_3 = 0;
for (int i = 1; i <= d11_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_3 = received_nr_3 + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(received_nr_3);
Serial.print("RECEIVED_NUMBER_4 = ");//print out LED data and convert to integer
received_nr_4 = 0;
for (int i = 1; i <= d12_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_4 = received_nr_4 + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(received_nr_4);
Serial.print("RECEIVED_NUMBER_5 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d13_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_5 = received_nr_5 + ((d13_from_ESP[i] - 48) * multiplier[d13_from_ESP[0] - i]);
}
Serial.println(received_nr_5);
Serial.print("RECEIVED_TEXT_1 = ");//print out LED data and convert to integer
received_text = "";
for (int i = 1; i <= d14_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_text = received_text + d14_from_ESP[i];
}
Serial.println(received_text);
Serial.println("");
//that's it!!
}//##
}//n6
}//##
}//n5
}//##
}//n4
}//##
}//n3
}//##
}//n2
}//##
}//n1
}//##
}//b5
}//##
}//b4
}//##
}//b3
}//##
}//b2
}//##
}//b1
}//##
}//t1
}//connect ESP
}//connect web host
void send_to_server_2() {
//we have changing variable here, so we need to first build up our URL packet
/*URL_withPacket = URL_webhost;//pull in the base URL
URL_withPacket += String(unit_id);//unit id value
URL_withPacket += "&sensor=";//unit id 1
URL_withPacket += String(sensor_value);//sensor value
URL_withPacket += payload_closer;*/
url = location_url;
url += NOOBIX_id;
url += "&pw=";
url += NOOBIX_password;//sensor value
url += "&un=2";
url += "&n2=";
url += String(sent_nr_2);//sensor value
URL_withPacket = "";
URL_withPacket = (String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
/*
URL_withPacket += "Host: www.electronoobs.com\r\n";
URL_withPacket += "Connection: close\r\n\r\n";
*/
/// This builds out the payload URL - not really needed here, but is very handy when adding different arrays to the payload
counter = 0; //keeps track of the payload size
payload_size = 0;
for (int i = 0; i < (URL_withPacket.length()); i++) { //using a string this time, so use .length()
payload[payload_size + i] = URL_withPacket[i]; //build up the payload
counter++;//increment the counter
}//for int
payload_size = counter + payload_size; //payload size is just the counter value - more on this when we need to build out the payload with more data
//for(int i=0; i<payload_size; i++)//print the payload to the ESP
//Serial.print(payload[i]);
if (connect_ESP()) { //this calls 'connect_ESP()' and expects a '1' back if successful
//nice, we're in and ready to look for data
//first up, we need to parse the returned data _t1123##_d15##_d210##
//Serial.println("connected ESP");
if (read_until_ESP(keyword_t1, sizeof(keyword_t1), 5000, 0)) { //go find t1 then stop
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //our data is next, so change mode to '1' and stop at ##
//got our data, so quickly store it away in d1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++) //go see 'setup' and how this was done with the ip address for more info
t1_from_ESP[i] = scratch_data_from_ESP[i];
t1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//we still have more data to get out of this stream, now we want d1
if (read_until_ESP(keyword_b1, sizeof(keyword_b1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d1_from_ESP[i] = scratch_data_from_ESP[i];
d1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b2, sizeof(keyword_b2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d2_from_ESP[i] = scratch_data_from_ESP[i];
d2_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b3, sizeof(keyword_b3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d3_from_ESP[i] = scratch_data_from_ESP[i];
d3_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b4, sizeof(keyword_b4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d4_from_ESP[i] = scratch_data_from_ESP[i];
d4_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b5, sizeof(keyword_b5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d5_from_ESP[i] = scratch_data_from_ESP[i];
d5_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n1, sizeof(keyword_n1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d9_from_ESP[i] = scratch_data_from_ESP[i];
d9_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n2, sizeof(keyword_n2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n3, sizeof(keyword_n3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n4, sizeof(keyword_n4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n5, sizeof(keyword_n5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d13_from_ESP[i] = scratch_data_from_ESP[i];
d13_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n6, sizeof(keyword_n6), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d14_from_ESP[i] = scratch_data_from_ESP[i];
d14_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.println("");
Serial.print("Time ");
if (t1_from_ESP[0] > 3) {
Serial.print(t1_from_ESP[1]);
Serial.print(t1_from_ESP[2]);
Serial.print(":");
Serial.print(t1_from_ESP[3]);
Serial.println(t1_from_ESP[4]);
}
else {
Serial.print(t1_from_ESP[1]);
Serial.print(":");
Serial.print(t1_from_ESP[2]);
Serial.println(t1_from_ESP[3]);
}
Serial.print("RECEIVED_BOOL_1 = ");//print out LED data and convert to integer
received_bool_1 = 0;
for (int i = 1; i <= d1_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_1 = received_bool_1 + ((d1_from_ESP[i] - 48) * multiplier[d1_from_ESP[0] - i]);
}
Serial.println(received_bool_1);
Serial.print("RECEIVED_BOOL_2 = ");//print out LED data and convert to integer
received_bool_2 = 0;
for (int i = 1; i <= d2_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_2 = received_bool_2 + ((d2_from_ESP[i] - 48) * multiplier[d2_from_ESP[0] - i]);
}
Serial.println(received_bool_2);
Serial.print("RECEIVED_BOOL_3 = ");//print out LED data and convert to integer
received_bool_3 = 0;
for (int i = 1; i <= d3_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_3 = received_bool_3 + ((d3_from_ESP[i] - 48) * multiplier[d3_from_ESP[0] - i]);
}
Serial.println(received_bool_3);
Serial.print("RECEIVED_BOOL_4 = ");//print out LED data and convert to integer
received_bool_4 = 0;
for (int i = 1; i <= d4_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_4 = received_bool_4 + ((d4_from_ESP[i] - 48) * multiplier[d4_from_ESP[0] - i]);
}
Serial.println(received_bool_4);
Serial.print("RECEIVED_BOOL_5 = ");//print out LED data and convert to integer
received_bool_5 = 0;
for (int i = 1; i <= d5_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_5 = received_bool_5 + ((d5_from_ESP[i] - 48) * multiplier[d5_from_ESP[0] - i]);
}
Serial.println(received_bool_5);
Serial.print("RECEIVED_NUMBER_1 = ");//print out LED data and convert to integer
received_nr_1 = 0;
for (int i = 1; i <= d9_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_1 = received_nr_1 + ((d9_from_ESP[i] - 48) * multiplier[d9_from_ESP[0] - i]);
}
Serial.println(received_nr_1);
Serial.print("RECEIVED_NUMBER_2 = ");//print out LED data and convert to integer
received_nr_2 = 0;
for (int i = 1; i <= d10_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_2 = received_nr_2 + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(received_nr_2);
Serial.print("RECEIVED_NUMBER_3 = ");//print out LED data and convert to integer
received_nr_3 = 0;
for (int i = 1; i <= d11_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_3 = received_nr_3 + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(received_nr_3);
Serial.print("RECEIVED_NUMBER_4 = ");//print out LED data and convert to integer
received_nr_4 = 0;
for (int i = 1; i <= d12_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_4 = received_nr_4 + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(received_nr_4);
Serial.print("RECEIVED_NUMBER_5 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d13_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_5 = received_nr_5 + ((d13_from_ESP[i] - 48) * multiplier[d13_from_ESP[0] - i]);
}
Serial.println(received_nr_5);
Serial.print("RECEIVED_TEXT_1 = ");//print out LED data and convert to integer
received_text = "";
for (int i = 1; i <= d14_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_text = received_text + d14_from_ESP[i];
}
Serial.println(received_text);
Serial.println("");
//that's it!!
}//##
}//n6 text 1
}//##
}//n5
}//##
}//n4
}//##
}//n3
}//##
}//n2
}//##
}//n1
}//##
}//b5
}//##
}//b4
}//##
}//b3
}//##
}//b2
}//##
}//b1
}//##
}//t1
/*
//Serial.println("connected ESP");
//we still have more data to get out of this stream, now we want d1
if(read_until_ESP(keyword_n2,sizeof(keyword_n2),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.print("SENT_NUMBER_2 = ");//print out LED data and convert to integer
sent_nr_2_feedback = 0;
for(int i=1; i<=d10_from_ESP[0]; i++){
//Serial.print(d1_from_ESP[i]);
sent_nr_2_feedback = sent_nr_2_feedback + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(sent_nr_2_feedback);
Serial.println("");
//that's it!!
}//##
}//d2
*/
}//connect ESP
}//connect web host
void send_to_server_3() {
//we have changing variable here, so we need to first build up our URL packet
/*URL_withPacket = URL_webhost;//pull in the base URL
URL_withPacket += String(unit_id);//unit id value
URL_withPacket += "&sensor=";//unit id 1
URL_withPacket += String(sensor_value);//sensor value
URL_withPacket += payload_closer;*/
url = location_url;
url += NOOBIX_id;
url += "&pw=";
url += NOOBIX_password;//sensor value
url += "&un=3";
url += "&n3=";
url += String(sent_nr_3);//sensor value
URL_withPacket = "";
URL_withPacket = (String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
/*
URL_withPacket += "Host: www.electronoobs.com\r\n";
URL_withPacket += "Connection: close\r\n\r\n";
*/
/// This builds out the payload URL - not really needed here, but is very handy when adding different arrays to the payload
counter = 0; //keeps track of the payload size
payload_size = 0;
for (int i = 0; i < (URL_withPacket.length()); i++) { //using a string this time, so use .length()
payload[payload_size + i] = URL_withPacket[i]; //build up the payload
counter++;//increment the counter
}//for int
payload_size = counter + payload_size; //payload size is just the counter value - more on this when we need to build out the payload with more data
//for(int i=0; i<payload_size; i++)//print the payload to the ESP
//Serial.print(payload[i]);
if (connect_ESP()) { //this calls 'connect_ESP()' and expects a '1' back if successful
//nice, we're in and ready to look for data
//first up, we need to parse the returned data _t1123##_d15##_d210##
//Serial.println("connected ESP");
if (read_until_ESP(keyword_t1, sizeof(keyword_t1), 5000, 0)) { //go find t1 then stop
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //our data is next, so change mode to '1' and stop at ##
//got our data, so quickly store it away in d1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++) //go see 'setup' and how this was done with the ip address for more info
t1_from_ESP[i] = scratch_data_from_ESP[i];
t1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//we still have more data to get out of this stream, now we want d1
if (read_until_ESP(keyword_b1, sizeof(keyword_b1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d1_from_ESP[i] = scratch_data_from_ESP[i];
d1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b2, sizeof(keyword_b2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d2_from_ESP[i] = scratch_data_from_ESP[i];
d2_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b3, sizeof(keyword_b3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d3_from_ESP[i] = scratch_data_from_ESP[i];
d3_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b4, sizeof(keyword_b4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d4_from_ESP[i] = scratch_data_from_ESP[i];
d4_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b5, sizeof(keyword_b5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d5_from_ESP[i] = scratch_data_from_ESP[i];
d5_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n1, sizeof(keyword_n1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d9_from_ESP[i] = scratch_data_from_ESP[i];
d9_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n2, sizeof(keyword_n2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n3, sizeof(keyword_n3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n4, sizeof(keyword_n4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n5, sizeof(keyword_n5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d13_from_ESP[i] = scratch_data_from_ESP[i];
d13_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n6, sizeof(keyword_n6), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d14_from_ESP[i] = scratch_data_from_ESP[i];
d14_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.println("");
Serial.print("Time ");
if (t1_from_ESP[0] > 3) {
Serial.print(t1_from_ESP[1]);
Serial.print(t1_from_ESP[2]);
Serial.print(":");
Serial.print(t1_from_ESP[3]);
Serial.println(t1_from_ESP[4]);
}
else {
Serial.print(t1_from_ESP[1]);
Serial.print(":");
Serial.print(t1_from_ESP[2]);
Serial.println(t1_from_ESP[3]);
}
Serial.print("RECEIVED_BOOL_1 = ");//print out LED data and convert to integer
received_bool_1 = 0;
for (int i = 1; i <= d1_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_1 = received_bool_1 + ((d1_from_ESP[i] - 48) * multiplier[d1_from_ESP[0] - i]);
}
Serial.println(received_bool_1);
Serial.print("RECEIVED_BOOL_2 = ");//print out LED data and convert to integer
received_bool_2 = 0;
for (int i = 1; i <= d2_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_2 = received_bool_2 + ((d2_from_ESP[i] - 48) * multiplier[d2_from_ESP[0] - i]);
}
Serial.println(received_bool_2);
Serial.print("RECEIVED_BOOL_3 = ");//print out LED data and convert to integer
received_bool_3 = 0;
for (int i = 1; i <= d3_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_3 = received_bool_3 + ((d3_from_ESP[i] - 48) * multiplier[d3_from_ESP[0] - i]);
}
Serial.println(received_bool_3);
Serial.print("RECEIVED_BOOL_4 = ");//print out LED data and convert to integer
received_bool_4 = 0;
for (int i = 1; i <= d4_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_4 = received_bool_4 + ((d4_from_ESP[i] - 48) * multiplier[d4_from_ESP[0] - i]);
}
Serial.println(received_bool_4);
Serial.print("RECEIVED_BOOL_5 = ");//print out LED data and convert to integer
received_bool_5 = 0;
for (int i = 1; i <= d5_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_5 = received_bool_5 + ((d5_from_ESP[i] - 48) * multiplier[d5_from_ESP[0] - i]);
}
Serial.println(received_bool_5);
Serial.print("RECEIVED_NUMBER_1 = ");//print out LED data and convert to integer
received_nr_1 = 0;
for (int i = 1; i <= d9_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_1 = received_nr_1 + ((d9_from_ESP[i] - 48) * multiplier[d9_from_ESP[0] - i]);
}
Serial.println(received_nr_1);
Serial.print("RECEIVED_NUMBER_2 = ");//print out LED data and convert to integer
received_nr_2 = 0;
for (int i = 1; i <= d10_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_2 = received_nr_2 + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(received_nr_2);
Serial.print("RECEIVED_NUMBER_3 = ");//print out LED data and convert to integer
received_nr_3 = 0;
for (int i = 1; i <= d11_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_3 = received_nr_3 + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(received_nr_3);
Serial.print("RECEIVED_NUMBER_4 = ");//print out LED data and convert to integer
received_nr_4 = 0;
for (int i = 1; i <= d12_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_4 = received_nr_4 + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(received_nr_4);
Serial.print("RECEIVED_NUMBER_5 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d13_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_5 = received_nr_5 + ((d13_from_ESP[i] - 48) * multiplier[d13_from_ESP[0] - i]);
}
Serial.println(received_nr_5);
Serial.print("RECEIVED_TEXT_1 = ");//print out LED data and convert to integer
received_text = "";
for (int i = 1; i <= d14_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_text = received_text + d14_from_ESP[i];
}
Serial.println(received_text);
Serial.println("");
//that's it!!
}//##
}//n6 text 1
}//##
}//n5
}//##
}//n4
}//##
}//n3
}//##
}//n2
}//##
}//n1
}//##
}//b5
}//##
}//b4
}//##
}//b3
}//##
}//b2
}//##
}//b1
}//##
}//t1
/*
//Serial.println("connected ESP");
//we still have more data to get out of this stream, now we want d1
if(read_until_ESP(keyword_n3,sizeof(keyword_n3),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.print("SENT_NUMBER_3 = ");//print out LED data and convert to integer
sent_nr_3_feedback = 0;
for(int i=1; i<=d11_from_ESP[0]; i++){
//Serial.print(d11_from_ESP[i]);
sent_nr_3_feedback = sent_nr_3_feedback + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(sent_nr_3_feedback);
Serial.println("");
//that's it!!
}//##
}//d2
*/
}//connect ESP
}//connect web host
void send_to_server_4() {
//we have changing variable here, so we need to first build up our URL packet
/*URL_withPacket = URL_webhost;//pull in the base URL
URL_withPacket += String(unit_id);//unit id value
URL_withPacket += "&sensor=";//unit id 1
URL_withPacket += String(sensor_value);//sensor value
URL_withPacket += payload_closer;*/
url = location_url;
url += NOOBIX_id;
url += "&pw=";
url += NOOBIX_password;//sensor value
url += "&un=4";
url += "&n4=";
url += String(sent_nr_4);//sensor value
URL_withPacket = "";
URL_withPacket = (String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
/*
URL_withPacket += "Host: www.electronoobs.com\r\n";
URL_withPacket += "Connection: close\r\n\r\n";
*/
/// This builds out the payload URL - not really needed here, but is very handy when adding different arrays to the payload
counter = 0; //keeps track of the payload size
payload_size = 0;
for (int i = 0; i < (URL_withPacket.length()); i++) { //using a string this time, so use .length()
payload[payload_size + i] = URL_withPacket[i]; //build up the payload
counter++;//increment the counter
}//for int
payload_size = counter + payload_size; //payload size is just the counter value - more on this when we need to build out the payload with more data
//for(int i=0; i<payload_size; i++)//print the payload to the ESP
//Serial.print(payload[i]);
if (connect_ESP()) { //this calls 'connect_ESP()' and expects a '1' back if successful
//nice, we're in and ready to look for data
//first up, we need to parse the returned data _t1123##_d15##_d210##
//Serial.println("connected ESP");
if (read_until_ESP(keyword_t1, sizeof(keyword_t1), 5000, 0)) { //go find t1 then stop
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //our data is next, so change mode to '1' and stop at ##
//got our data, so quickly store it away in d1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++) //go see 'setup' and how this was done with the ip address for more info
t1_from_ESP[i] = scratch_data_from_ESP[i];
t1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//we still have more data to get out of this stream, now we want d1
if (read_until_ESP(keyword_b1, sizeof(keyword_b1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d1_from_ESP[i] = scratch_data_from_ESP[i];
d1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b2, sizeof(keyword_b2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d2_from_ESP[i] = scratch_data_from_ESP[i];
d2_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b3, sizeof(keyword_b3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d3_from_ESP[i] = scratch_data_from_ESP[i];
d3_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b4, sizeof(keyword_b4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d4_from_ESP[i] = scratch_data_from_ESP[i];
d4_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b5, sizeof(keyword_b5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d5_from_ESP[i] = scratch_data_from_ESP[i];
d5_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n1, sizeof(keyword_n1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d9_from_ESP[i] = scratch_data_from_ESP[i];
d9_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n2, sizeof(keyword_n2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n3, sizeof(keyword_n3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n4, sizeof(keyword_n4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n5, sizeof(keyword_n5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d13_from_ESP[i] = scratch_data_from_ESP[i];
d13_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n6, sizeof(keyword_n6), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d14_from_ESP[i] = scratch_data_from_ESP[i];
d14_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.println("");
Serial.print("Time ");
if (t1_from_ESP[0] > 3) {
Serial.print(t1_from_ESP[1]);
Serial.print(t1_from_ESP[2]);
Serial.print(":");
Serial.print(t1_from_ESP[3]);
Serial.println(t1_from_ESP[4]);
}
else {
Serial.print(t1_from_ESP[1]);
Serial.print(":");
Serial.print(t1_from_ESP[2]);
Serial.println(t1_from_ESP[3]);
}
Serial.print("RECEIVED_BOOL_1 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d1_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_1 = received_bool_1 + ((d1_from_ESP[i] - 48) * multiplier[d1_from_ESP[0] - i]);
}
Serial.println(received_bool_1);
Serial.print("RECEIVED_BOOL_2 = ");//print out LED data and convert to integer
received_bool_2 = 0;
for (int i = 1; i <= d2_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_2 = received_bool_2 + ((d2_from_ESP[i] - 48) * multiplier[d2_from_ESP[0] - i]);
}
Serial.println(received_bool_2);
Serial.print("RECEIVED_BOOL_3 = ");//print out LED data and convert to integer
received_bool_3 = 0;
for (int i = 1; i <= d3_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_3 = received_bool_3 + ((d3_from_ESP[i] - 48) * multiplier[d3_from_ESP[0] - i]);
}
Serial.println(received_bool_3);
Serial.print("RECEIVED_BOOL_4 = ");//print out LED data and convert to integer
received_bool_4 = 0;
for (int i = 1; i <= d4_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_4 = received_bool_4 + ((d4_from_ESP[i] - 48) * multiplier[d4_from_ESP[0] - i]);
}
Serial.println(received_bool_4);
Serial.print("RECEIVED_BOOL_5 = ");//print out LED data and convert to integer
received_bool_5 = 0;
for (int i = 1; i <= d5_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_5 = received_bool_5 + ((d5_from_ESP[i] - 48) * multiplier[d5_from_ESP[0] - i]);
}
Serial.println(received_bool_5);
Serial.print("RECEIVED_NUMBER_1 = ");//print out LED data and convert to integer
received_nr_1 = 0;
for (int i = 1; i <= d9_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_1 = received_nr_1 + ((d9_from_ESP[i] - 48) * multiplier[d9_from_ESP[0] - i]);
}
Serial.println(received_nr_1);
Serial.print("RECEIVED_NUMBER_2 = ");//print out LED data and convert to integer
received_nr_2 = 0;
for (int i = 1; i <= d10_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_2 = received_nr_2 + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(received_nr_2);
Serial.print("RECEIVED_NUMBER_3 = ");//print out LED data and convert to integer
received_nr_3 = 0;
for (int i = 1; i <= d11_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_3 = received_nr_3 + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(received_nr_3);
Serial.print("RECEIVED_NUMBER_4 = ");//print out LED data and convert to integer
received_nr_4 = 0;
for (int i = 1; i <= d12_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_4 = received_nr_4 + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(received_nr_4);
Serial.print("RECEIVED_NUMBER_5 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d13_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_5 = received_nr_5 + ((d13_from_ESP[i] - 48) * multiplier[d13_from_ESP[0] - i]);
}
Serial.println(received_nr_5);
Serial.print("RECEIVED_TEXT_1 = ");//print out LED data and convert to integer
received_text = "";
for (int i = 1; i <= d14_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_text = received_text + d14_from_ESP[i];
}
Serial.println(received_text);
Serial.println("");
//that's it!!
}//##
}//n6 text 1
}//##
}//n5
}//##
}//n4
}//##
}//n3
}//##
}//n2
}//##
}//n1
}//##
}//b5
}//##
}//b4
}//##
}//b3
}//##
}//b2
}//##
}//b1
}//##
}//t1
/*
//Serial.println("connected ESP");
//we still have more data to get out of this stream, now we want d1
if(read_until_ESP(keyword_n4,sizeof(keyword_n4),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.print("SENT_NUMBER_4 = ");//print out LED data and convert to integer
sent_nr_4_feedback = 0;
for(int i=1; i<=d12_from_ESP[0]; i++){
//Serial.print(d12_from_ESP[i]);
sent_nr_4_feedback = sent_nr_4_feedback + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(sent_nr_4_feedback);
Serial.println("");
//that's it!!
}//##
}//d2
*/
}//connect ESP
}//connect web host
void send_to_server_5() {
//we have changing variable here, so we need to first build up our URL packet
/*URL_withPacket = URL_webhost;//pull in the base URL
URL_withPacket += String(unit_id);//unit id value
URL_withPacket += "&sensor=";//unit id 1
URL_withPacket += String(sensor_value);//sensor value
URL_withPacket += payload_closer;*/
url = location_url;
url += NOOBIX_id;
url += "&pw=";
url += NOOBIX_password;//sensor value
url += "&un=5";
url += "&b6=";
url += String(sent_bool_1);//sensor value
url += "&b7=";
url += String(sent_bool_2);//sensor value
url += "&b8=";
url += String(sent_bool_3);//sensor value
URL_withPacket = "";
URL_withPacket = (String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
/*
URL_withPacket += "Host: www.electronoobs.com\r\n";
URL_withPacket += "Connection: close\r\n\r\n";
*/
/// This builds out the payload URL - not really needed here, but is very handy when adding different arrays to the payload
counter = 0; //keeps track of the payload size
payload_size = 0;
for (int i = 0; i < (URL_withPacket.length()); i++) { //using a string this time, so use .length()
payload[payload_size + i] = URL_withPacket[i]; //build up the payload
counter++;//increment the counter
}//for int
payload_size = counter + payload_size; //payload size is just the counter value - more on this when we need to build out the payload with more data
//for(int i=0; i<payload_size; i++)//print the payload to the ESP
//Serial.print(payload[i]);
if (connect_ESP()) { //this calls 'connect_ESP()' and expects a '1' back if successful
//nice, we're in and ready to look for data
//first up, we need to parse the returned data _t1123##_d15##_d210##
//Serial.println("connected ESP");
if (read_until_ESP(keyword_t1, sizeof(keyword_t1), 5000, 0)) { //go find t1 then stop
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //our data is next, so change mode to '1' and stop at ##
//got our data, so quickly store it away in d1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++) //go see 'setup' and how this was done with the ip address for more info
t1_from_ESP[i] = scratch_data_from_ESP[i];
t1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//we still have more data to get out of this stream, now we want d1
if (read_until_ESP(keyword_b1, sizeof(keyword_b1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d1_from_ESP[i] = scratch_data_from_ESP[i];
d1_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b2, sizeof(keyword_b2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d2_from_ESP[i] = scratch_data_from_ESP[i];
d2_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b3, sizeof(keyword_b3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d3_from_ESP[i] = scratch_data_from_ESP[i];
d3_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b4, sizeof(keyword_b4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d4_from_ESP[i] = scratch_data_from_ESP[i];
d4_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_b5, sizeof(keyword_b5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d5_from_ESP[i] = scratch_data_from_ESP[i];
d5_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n1, sizeof(keyword_n1), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d9_from_ESP[i] = scratch_data_from_ESP[i];
d9_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n2, sizeof(keyword_n2), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d10_from_ESP[i] = scratch_data_from_ESP[i];
d10_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n3, sizeof(keyword_n3), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d11_from_ESP[i] = scratch_data_from_ESP[i];
d11_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n4, sizeof(keyword_n4), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d12_from_ESP[i] = scratch_data_from_ESP[i];
d12_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n5, sizeof(keyword_n5), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d13_from_ESP[i] = scratch_data_from_ESP[i];
d13_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
if (read_until_ESP(keyword_n6, sizeof(keyword_n6), 5000, 0)) { //same as before - first d1
if (read_until_ESP(keyword_doublehash, sizeof(keyword_doublehash), 5000, 1)) { //now ## and mode=1
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1); i++)
d14_from_ESP[i] = scratch_data_from_ESP[i];
d14_from_ESP[0] = (scratch_data_from_ESP[0] - sizeof(keyword_doublehash) + 1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.println("");
Serial.print("Time ");
if (t1_from_ESP[0] > 3) {
Serial.print(t1_from_ESP[1]);
Serial.print(t1_from_ESP[2]);
Serial.print(":");
Serial.print(t1_from_ESP[3]);
Serial.println(t1_from_ESP[4]);
}
else {
Serial.print(t1_from_ESP[1]);
Serial.print(":");
Serial.print(t1_from_ESP[2]);
Serial.println(t1_from_ESP[3]);
}
Serial.print("RECEIVED_BOOL_1 = ");//print out LED data and convert to integer
received_bool_1 = 0;
for (int i = 1; i <= d1_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_1 = received_bool_1 + ((d1_from_ESP[i] - 48) * multiplier[d1_from_ESP[0] - i]);
}
Serial.println(received_bool_1);
Serial.print("RECEIVED_BOOL_2 = ");//print out LED data and convert to integer
received_bool_2 = 0;
for (int i = 1; i <= d2_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_2 = received_bool_2 + ((d2_from_ESP[i] - 48) * multiplier[d2_from_ESP[0] - i]);
}
Serial.println(received_bool_2);
Serial.print("RECEIVED_BOOL_3 = ");//print out LED data and convert to integer
received_bool_3 = 0;
for (int i = 1; i <= d3_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_3 = received_bool_3 + ((d3_from_ESP[i] - 48) * multiplier[d3_from_ESP[0] - i]);
}
Serial.println(received_bool_3);
Serial.print("RECEIVED_BOOL_4 = ");//print out LED data and convert to integer
received_bool_4 = 0;
for (int i = 1; i <= d4_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_4 = received_bool_4 + ((d4_from_ESP[i] - 48) * multiplier[d4_from_ESP[0] - i]);
}
Serial.println(received_bool_4);
Serial.print("RECEIVED_BOOL_5 = ");//print out LED data and convert to integer
received_bool_5 = 0;
for (int i = 1; i <= d5_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_bool_5 = received_bool_5 + ((d5_from_ESP[i] - 48) * multiplier[d5_from_ESP[0] - i]);
}
Serial.println(received_bool_5);
Serial.print("RECEIVED_NUMBER_1 = ");//print out LED data and convert to integer
received_nr_1 = 0;
for (int i = 1; i <= d9_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_1 = received_nr_1 + ((d9_from_ESP[i] - 48) * multiplier[d9_from_ESP[0] - i]);
}
Serial.println(received_nr_1);
Serial.print("RECEIVED_NUMBER_2 = ");//print out LED data and convert to integer
received_nr_2 = 0;
for (int i = 1; i <= d10_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_2 = received_nr_2 + ((d10_from_ESP[i] - 48) * multiplier[d10_from_ESP[0] - i]);
}
Serial.println(received_nr_2);
Serial.print("RECEIVED_NUMBER_3 = ");//print out LED data and convert to integer
received_nr_3 = 0;
for (int i = 1; i <= d11_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_3 = received_nr_3 + ((d11_from_ESP[i] - 48) * multiplier[d11_from_ESP[0] - i]);
}
Serial.println(received_nr_3);
Serial.print("RECEIVED_NUMBER_4 = ");//print out LED data and convert to integer
received_nr_4 = 0;
for (int i = 1; i <= d12_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_4 = received_nr_4 + ((d12_from_ESP[i] - 48) * multiplier[d12_from_ESP[0] - i]);
}
Serial.println(received_nr_4);
Serial.print("RECEIVED_NUMBER_5 = ");//print out LED data and convert to integer
received_nr_5 = 0;
for (int i = 1; i <= d13_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_nr_5 = received_nr_5 + ((d13_from_ESP[i] - 48) * multiplier[d13_from_ESP[0] - i]);
}
Serial.println(received_nr_5);
Serial.print("RECEIVED_TEXT_1 = ");//print out LED data and convert to integer
received_text = "";
for (int i = 1; i <= d14_from_ESP[0]; i++) {
//Serial.print(d12_from_ESP[i]);
received_text = received_text + d14_from_ESP[i];
}
Serial.println(received_text);
Serial.println("");
//that's it!!
}//##
}//n6 text 1
}//##
}//n5
}//##
}//n4
}//##
}//n3
}//##
}//n2
}//##
}//n1
}//##
}//b5
}//##
}//b4
}//##
}//b3
}//##
}//b2
}//##
}//b1
}//##
}//t1
/*
//Serial.println("connected ESP");
//we still have more data to get out of this stream, now we want d1
if(read_until_ESP(keyword_b6,sizeof(keyword_b6),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d6_from_ESP[i] = scratch_data_from_ESP[i];
d6_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
if(read_until_ESP(keyword_b7,sizeof(keyword_b7),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d7_from_ESP[i] = scratch_data_from_ESP[i];
d7_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
if(read_until_ESP(keyword_b8,sizeof(keyword_b8),5000,0)){//same as before - first d1
if(read_until_ESP(keyword_doublehash,sizeof(keyword_doublehash),5000,1)){//now ## and mode=1
for(int i=1; i<=(scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1); i++)
d8_from_ESP[i] = scratch_data_from_ESP[i];
d8_from_ESP[0] = (scratch_data_from_ESP[0]-sizeof(keyword_doublehash)+1);
//now that we have our data, go wait for the connection to disconnect
//- the ESP will eventually return 'Unlink'
//delay(10);
Serial.println("FOUND DATA & DISCONNECTED");
serial_dump_ESP();//now we can clear out the buffer and read whatever is still there
//let's see how the data looks
Serial.print("SENT_BOOL_1 = ");//print out LED data and convert to integer
sent_bool_1_feedback = 0;
for(int i=1; i<=d6_from_ESP[0]; i++){
//Serial.print(d12_from_ESP[i]);
sent_bool_1_feedback = sent_bool_1_feedback + ((d6_from_ESP[i] - 48) * multiplier[d6_from_ESP[0] - i]);
}
Serial.println(sent_bool_1_feedback);
Serial.print("SENT_BOOL_2 = ");//print out LED data and convert to integer
sent_bool_2_feedback = 0;
for(int i=1; i<=d7_from_ESP[0]; i++){
//Serial.print(d12_from_ESP[i]);
sent_bool_2_feedback = sent_bool_2_feedback + ((d7_from_ESP[i] - 48) * multiplier[d7_from_ESP[0] - i]);
}
Serial.println(sent_bool_1_feedback);
Serial.print("SENT_BOOL_3 = ");//print out LED data and convert to integer
sent_bool_3_feedback = 0;
for(int i=1; i<=d8_from_ESP[0]; i++){
//Serial.print(d12_from_ESP[i]);
sent_bool_3_feedback = sent_bool_3_feedback + ((d8_from_ESP[i] - 48) * multiplier[d8_from_ESP[0] - i]);
}
Serial.println(sent_bool_3_feedback);
Serial.println("");
//that's it!!
}//##
}//b8
}//##
}//b7
}//##
}//b6
*/
}//connect ESP
}//connect web host
//pretty simple function - read everything out of the serial buffer and whats coming and get rid of it
void serial_dump_ESP() {
char temp;
while (ESP8266.available()) {
temp = ESP8266.read();
delay(1);//could play around with this value if buffer overflows are occuring
}//while
//Serial.println("DUMPED");
}//serial dump
boolean setup_ESP() { //returns a '1' if successful
ESP8266.print("AT\r\n");// Send just 'AT' to make sure the ESP is responding
//this read_until_... function is used to find a keyword in the ESP response - more on this later and in the function itself
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) //go look for keyword "OK" with a 5sec timeout
Serial.println("ESP CHECK OK");
else
Serial.println("ESP CHECK FAILED");
serial_dump_ESP();//this just reads everything in the buffer and what's still coming from the ESP
ESP8266.print("AT+RST\r\n");// Give it a reset - who knows what condition it was in, better to start fresh
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) //go look for keyword "Ready" - takes a few seconds longer to complete
Serial.println("ESP RESET OK");//depneding on the FW version on the ESP, sometimes the Ready is with a lowercase r - ready
else
Serial.println("ESP RESET FAILED");
serial_dump_ESP();
ESP8266.print("AT+CWMODE=");// set the CWMODE
ESP8266.print(CWMODE);//just send what is set in the constant
ESP8266.print("\r\n");
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) //go look for keyword "OK"
Serial.println("ESP CWMODE SET");
else
Serial.println("ESP CWMODE SET FAILED"); //probably going to fail, since a 'no change' is returned if already set - would be nice to check for two words
serial_dump_ESP();
//Here's where the SSID and PW are set
ESP8266.print("AT+CWJAP=\"");// set the SSID AT+CWJAP="SSID","PW"
ESP8266.print(SSID_ESP);//from constant
ESP8266.print("\",\"");
ESP8266.print(SSID_KEY);//form constant
ESP8266.print("\"\r\n");
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 10000, 0)) //go look for keyword "OK"
Serial.println("ESP SSID SET OK");
else
Serial.println("ESP SSID SET FAILED");
serial_dump_ESP();
//This checks for and stores the IP address
Serial.println("CHECKING FOR AN IP ADDRESS");
ESP8266.print("AT+CIFSR\r\n");//command to retrieve IP address from ESP
if (read_until_ESP(keyword_rn, sizeof(keyword_rn), 10000, 0)) { //look for first \r\n after AT+CIFSR echo - note mode is '0', the ip address is right after this
if (read_until_ESP(keyword_rn, sizeof(keyword_rn), 1000, 1)) { //look for second \r\n, and store everything it receives, mode='1'
//store the ip adress in its variable, ip_address[]
for (int i = 1; i <= (scratch_data_from_ESP[0] - sizeof(keyword_rn) + 1); i++) //that i<=... is going to take some explaining, see next lines
ip_address[i] = scratch_data_from_ESP[i];//fill up ip_address with the scratch data received
//i=1 because i=0 is the length of the data found between the two keywords, BUT this includes the length of the second keyword, so i<= to the length minus
//size of teh keyword, but remember, sizeof() will return one extra, which is going to be subtracted, so I just added it back in +1
ip_address[0] = (scratch_data_from_ESP[0] - sizeof(keyword_rn) + 1); //store the length of ip_address in [0], same thing as before
Serial.print("IP ADDRESS = ");//print it off to verify
for (int i = 1; i <= ip_address[0]; i++) //send out the ip address
Serial.print(ip_address[i]);
Serial.println("");
}
}//if first \r\n
else
Serial.print("IP ADDRESS FAIL");
serial_dump_ESP();
ESP8266.print("AT+CIPMUX=");// set the CIPMUX
ESP8266.print(CIPMUX);//from constant
ESP8266.print("\r\n");
if (read_until_ESP(keyword_OK, sizeof(keyword_OK), 5000, 0)) //go look for keyword "OK" or "no change
Serial.println("ESP CIPMUX SET");
else
Serial.println("ESP CIPMUX SET FAILED");
serial_dump_ESP();
//that's it! Could be done by nesting everything together, so if one thing fails, it returns '0', and if it gets all the way through it returns '1'...oh well
}//setup ESP