Previously I have asked this question in the forum, however, my explanation was not so clear and may result in confusion. Hence, I decided to rephrase my question in this new post.
Currently, I have been researching on how to allow my Zybo z720 board to receive data from Thingspeak channel through using Pmod ESP32 and control the status of the LED according to the data of Thingspeak. I have already known how to send the data (collected from ALS, AQS and HYGRO) from the zybo board to Thingspeak by using the AT command. I will show the code below.
Beforehand, I have tried this project with the NodeMCU since I thought the code I used for NodeMCU should be similar to ESP32. It worked perfectly. As I changed the thingspeak data link and updated the data, I can see my LED light up or light off. However, while I analysed the NodeMCU code, it does not use AT command and it also does not have any relationship with the code I used for sending data to Thingspeak.
So, do I need to use the same AT command, or I need to use something like Json parsing to accomplish that?
Question
helloworld1029
Previously I have asked this question in the forum, however, my explanation was not so clear and may result in confusion. Hence, I decided to rephrase my question in this new post.
Currently, I have been researching on how to allow my Zybo z720 board to receive data from Thingspeak channel through using Pmod ESP32 and control the status of the LED according to the data of Thingspeak. I have already known how to send the data (collected from ALS, AQS and HYGRO) from the zybo board to Thingspeak by using the AT command. I will show the code below.
void receiveData(XTime time){
XTime tEnd, tCur;
u8 recv_buffer=0;
u32 num_received=0;
XTime_GetTime(&tCur);
tEnd = tCur + (time * COUNTS_PER_SECOND);
do
{
num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
if(num_received >0){
num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
xil_printf("%c", recv_buffer);
}
if(tCur == tCur + COUNTS_PER_SECOND){
countdown = countdown -1;
}
else
XTime_GetTime(&tCur);
} while (tCur < tEnd);
}
void setWifiMode(void){
u8 tx[]="AT+CWMODE=3\r\n";
u32 num = strlen((char *) tx);
xil_printf((char *) tx);
ESP32_SendBuffer(&ESP32, tx, num);
usleep(100);
receiveData(3);
}
void connectWifi(void){
u8 tx[] = "AT+CWJAP=\"xxxxx\",\"xxxxxx"\r\n";
u32 num = strlen((char *) tx);
xil_printf((char *) tx);
ESP32_SendBuffer(&ESP32, tx, num);
usleep(100);
receiveData(30);
}
void establishConnection(void){
u8 tx[] = "AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n";
u32 num = strlen((char *) tx);
xil_printf((char *) tx);
ESP32_SendBuffer(&ESP32, tx, num);
receiveData(10);
}
void cipsend(float temp, u16 co2, u8 light, float humidity){
u8 command[150];
u8 finalcmd[50];
//field1 Ph field2 Temp field3 co2 field4 humidity field5 light
sprintf((char*)command, "GET http://api.thingspeak.com/update?api_key=xxxxxxxxxxxxx&field1=0&field2=%d.%02d&field3=%d&field4=%d.%02d&field5=%d\r\n"
,(int) temp_degc,((int) (temp_degc * 100)) % 100,co2,(int) hum_perrh,((int) (hum_perrh * 100)) % 100,light);
u32 length = strlen((char*)command);
sprintf((char*)finalcmd, "AT+CIPSEND=%d\r\n", (int)length);
u32 cmdlength =strlen((char*)finalcmd);
xil_printf("Length %d\r\n", length);
xil_printf((char *)finalcmd);
ESP32_SendBuffer(&ESP32, finalcmd, cmdlength);
sleep(1);
xil_printf((char *)command);
ESP32_SendBuffer(&ESP32, command, length);
receiveData(4);
}
Beforehand, I have tried this project with the NodeMCU since I thought the code I used for NodeMCU should be similar to ESP32. It worked perfectly. As I changed the thingspeak data link and updated the data, I can see my LED light up or light off. However, while I analysed the NodeMCU code, it does not use AT command and it also does not have any relationship with the code I used for sending data to Thingspeak.
So, do I need to use the same AT command, or I need to use something like Json parsing to accomplish that?
I will show all my work I have done below.
Thanks
Cpp Code Update 1.txt Arduino IoT Control.txt
Edited by helloworld1029Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now