Hi guys,
Recently I am using ESP8266 to delivery some message to the Azure Cloud.
In my sketch, I am tyring to use AT+ command to let my esp switch the case and do what I want it to do.
I have attached my code, I really wish someone could give me a hand. I used the right power supply and I have more than 30% memory. I do not know what happens.
I suspect on several things:
1)is that because I used too many while loops
2) char *I used several times in the loop but with different name as you can see in the code
I defined four char *, two of them are at :
char* store_serial_data[100]={};
char AlertPayload[100]={};
myStringTwo.toCharArray(AlertPayload, sizeof(AlertPayload));
Serial.print(myStringTwo);
char delimiter[]=",";
char* save_alert = strtok(AlertPayload,delimiter);
store_serial_data[alert_index]=save_alert;
Serial.print(store_serial_data*);*
while(save_alert!=NULL)
{
alert_index++;
save_alert=strtok(NULL,delimiter);
store_serial_data[alert_index]=save_alert;
Serial.print(store_serial_data*);
Serial.print("\n");
_}_
_
two of them are at :
_
char store_serial_data_normal[100]={};
char AlertPayload[100]={};
Serial.print(myStringTwo);
myStringTwo.toCharArray(AlertPayload, sizeof(AlertPayload));
Serial.write("\n debuger 1");
char delimiter[]=",";
char save_normal = strtok(AlertPayload,delimiter);
store_serial_data_normal[normal_index]=save_normal;
Serial.println(store_serial_data_normal[normal_index]);
while(save_normal!=NULL)
{
normal_index++;
Serial.write("\n debuger 5");
save_normal=strtok(NULL,delimiter);
store_serial_data_normal[normal_index]=save_normal;
Serial.println("\n");
Serial.println(store_serial_data_normal[normal_index]);
}
******************************************************
However, I have kept seeing the following message when I try to push the message to the clound,
someone also says might because ESPWebserver and HTTP request taking place at the same time but I doubt.
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
ctx: cont
sp: 3fff3b40 end: 3fff4440 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v4024c5b0
~ld
[code][code]
[/code][/code]
i really hope some one can help me.
```
*void setup() {
delay(1000);
Serial.begin(115200);
}
void loop()
{
if (Serial.available())
{
String c = Serial.readString();
if (c=="AT+ALERT")
{
state = Alert_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
Serial.write("\n Transmission Notice Mode");
Serial.flush();
}
switch(case)
{
case Alert_st:
message_check=0;
Serial.write("AT+ACK");
while(AlertLoop==0)
{
delay(250);
if(Serial.available())
{
int alert_index=0;
String myString= Serial.readStringUntil('\n');
//{911,3,1,0,22.5}
Serial.print(myString);
Serial.write("\n debuger 1");
int firstClosingBracket = myString.indexOf('{');
myString.remove(firstClosingBracket, 1);
String myStringTwo=myString;
int SecondClosingBracket = myString.indexOf('}');
myStringTwo.remove(SecondClosingBracket, 1);
char* store_serial_data[100]={};
char AlertPayload[100]={};
myStringTwo.toCharArray(AlertPayload, sizeof(AlertPayload));
Serial.print(myStringTwo);
char delimiter[]=",";
char* save_alert = strtok(AlertPayload,delimiter);
store_serial_data[alert_index]=save_alert;
Serial.print(store_serial_data[i]);
while(save_alert!=NULL)
{
alert_index++;
save_alert=strtok(NULL,delimiter);
store_serial_data[alert_index]=save_alert;
Serial.print(store_serial_data[i]);
Serial.print("\n");
}
if (String(store_serial_data[0])=="911")
{
alert_temperature = String(store_serial_data[4]).toFloat();
my_alert_b1=String(store_serial_data[2]).toFloat();
my_alert_b0=String(store_serial_data[3]).toFloat();
Serial.print("alert_temperature:\n");
Serial.print(alert_temperature);
system_rtc_mem_write(77, &alert_temperature, 4);
system_rtc_mem_write(81, &my_alert_b1, 1);
system_rtc_mem_write(82, &my_alert_b0, 1);
Serial.write("AT+ACK");
}
else
{
Serial.write("AT+NACK");
state=init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
ESP.deepSleep(sleep_t);
}
Serial.write("\n debuger 2");
while(AlertLoop==0)
{
delay(250);
Serial.write("\n debuger 3");
delay(250);
if(Serial.available())
{
int normal_index=0;
String myString= Serial.readStringUntil('\n');
Serial.print(myString);
//{400,3,25.20,24.30,25.90,500,1,20}
int firstClosingBracket = myString.indexOf('{');
myString.remove(firstClosingBracket, 1);
String myStringTwo=myString;
int SecondClosingBracket = myStringTwo.indexOf('}');
myStringTwo.remove(SecondClosingBracket, 1);
char* store_serial_data_normal[100]={};
char AlertPayload[100]={};
Serial.print(myStringTwo);
myStringTwo.toCharArray(AlertPayload, sizeof(AlertPayload));
Serial.write("\n debuger 1");
char delimiter[]=",";
char* save_normal = strtok(AlertPayload,delimiter);
store_serial_data_normal[normal_index]=save_normal;
Serial.println(store_serial_data_normal[normal_index]);
while(save_normal!=NULL)
{
normal_index++;
Serial.write("\n debuger 5");
save_normal=strtok(NULL,delimiter);
store_serial_data_normal[normal_index]=save_normal;
Serial.println("\n");
Serial.println(store_serial_data_normal[normal_index]);
}
if (String(store_serial_data_normal[0])=="400")
{
int dataLength = String(store_serial_data_normal[1]).toInt();
Serial.print(dataLength);
system_rtc_mem_write(80, &dataLength, 4);
for(j=0;j<dataLength;j++)
{
store_location=65+j;
data_s4= String(store_serial_data_normal[2+j]).toFloat();
system_rtc_mem_write(store_location, &data_s4, 4);
Serial.println("\n");
Serial.println(temp_data);
delay(250);
}
Serial.print("I am printing J\n");
Serial.print(j);
battery_data=String(store_serial_data_normal[dataLength+4]).toInt();
system_rtc_mem_write(78, &battery_data, 1);
Serial.write("AT+ACK");
start_t=millis();
while (AlertLoop==0)
{
Serial.write("\n debuger 4");
delay(250);
if (Serial.available())
{
String myString = Serial.readString();
if(myString=="AT+WIFISTART")
{
state=Wifi_init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
AlertLoop=1;
}
}
if (millis()-start_t>timesout)
{
Serial.write("AT+NACK");
state=init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
ESP.deepSleep(sleep_t);
}
yield();
}
}
else if (String(store_serial_data_normal[0])=="500")
{
dataLength=0;
system_rtc_mem_write(80, &dataLength, 4);
battery_data=String(store_serial_data_normal[2]).toInt();
system_rtc_mem_write(78, &battery_data, 1);
Serial.write("AT+ACK");
while (AlertLoop==0)
{
delay(250);
if (Serial.available())
{
String myString = Serial.readString();
if(myString=="AT+WIFISTART")
{
state=Wifi_init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
AlertLoop=1;
}
}
if (millis()-start_t>timesout)
{
Serial.write("AT+NACK");
state=init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
ESP.deepSleep(sleep_t);
}
yield();
}
}
else
{
Serial.write("AT+NACK");
state=init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
ESP.deepSleep(sleep_t);
}
}
if (millis()-start_t>timesout)
{
state=init_st;
ESP.deepSleep(sleep_t);
}
yield();
}
}
if (millis()-start_t>timesout)
{
state=init_st;
ESP.deepSleep(sleep_t);
}
yield();
}
break;
case init_st:
Serial.write("\n Initial State");
//sleep here;
delay(5000);
break;
default:
state = init_st;
system_rtc_mem_write(RTCMEMSTR, &state, 1);
break;
}
}
_```_
_Cao.h (9.4 KB)*_