Jump to content
  • 0

[Pmod ESP32] Problem with AT commands: Cannot receive IPD from the Serial Terminal


helloworld1029

Question

Hi, I am using Pmod ESP32 and figure out the possibilities to receive data from Thingspeak.

Based on my research, I found this link may help me to get Thingspeak data via using AT command.

The link is here:

https://allaboutfpga.com/remote-monitoring-and-control-of-home-appliances-from-cloud-using-edge-artix-7-fpga-board/

Remote Monitoring and control of Home appliances from cloud using EDGE Artix 7 FPGA board (allaboutfpga.com).

This picture (picture is from the link above) tells me what AT command I should use for receiving data from Thingspeak Cloud. 

image.thumb.png.a5717d09b84f8c52e6fe4535d75d1c9e.png

 

 

I used the above-mentioned AT comments like "AT+CIPSEND=69"

and "GET /channels/xxxxxxx/fields/1.json?results=1" to do the job. But I can't get the result I want. I expect there will be

+IPD, <num of bits>:data rather than "Send OK" and "Recv xx bytes"

These are the code: 

#include "xil_cache.h"
#include "xparameters.h"
#include "stdio.h"
#include "xparameters.h"
#include "xuartps.h"
#include "xtime_l.h"
#include "xgpiops.h"

extern "C"{


#include "PmodESP32.h"
}
/******************************************************************************/
/*                                                                            */
/* Defines  																  */
/*                                                                            */
/******************************************************************************/
#define HOST_UART_DEVICE_ID XPAR_PS7_UART_1_DEVICE_ID
#define HostUart XUartPs
#define HostUart_Config XUartPs_Config
#define HostUart_CfgInitialize XUartPs_CfgInitialize
#define HostUart_LookupConfig XUartPs_LookupConfig
#define HostUart_Recv XUartPs_Recv
#define HostUartConfig_GetBaseAddr(CfgPtr) (CfgPtr->BaseAddress)
#define PMODESP32_UART_BASEADDR XPAR_PMODESP32_0_AXI_LITE_UART_BASEADDR
#define PMODESP32_GPIO_BASEADDR XPAR_PMODESP32_0_AXI_LITE_GPIO_BASEADDR
#define COUNTS_PER_SECOND	(XPAR_CPU_CORTEXA9_CORE_CLOCK_FREQ_HZ /2)
#define TIMER_FREQ_HZ 100000000
#define MAX_WIDTH 320
#define MAX_HEIGHT 240
#define MAX_BUTTON 16
/******************************************************************************/
/*																			  */
/* Function Declarations         											  */
/*                                                                            */
/******************************************************************************/
void EnableCaches();
void DisableCaches();
void startup();
void receiveData(XTime time);
void setWifiMode(void);
void connectWifi(void);
void establishConnection(void);
void cipsend(void);
/******************************************************************************/
/*                                                                            */
/* Variables 																  */
/*                                                                            */
/******************************************************************************/

HostUart myHostUart;
XGpioPs_Config *ConfigPtr;
XGpioPs output;
XTime TimeStart;
XTime TimeEnd;
PmodESP32 ESP32;


int countdown =60;
char counter[20];


int main() {
   EnableCaches();
   startup();

   setWifiMode();
   xil_printf("Init Started\n\r");
   connectWifi();
   xil_printf("Wifi Done\n\r");

  // sleep(2);

   XTime_GetTime(&TimeStart);
   TimeEnd = TimeStart + ((XTime)COUNTS_PER_SECOND);
   establishConnection();

   cipsend();






   DisableCaches();
   return 0;
}

void startup(){



	   //Init ESP32
	   HostUart_Config *CfgPtr;
	   ESP32_Initialize(&ESP32, PMODESP32_UART_BASEADDR, PMODESP32_GPIO_BASEADDR);
	   CfgPtr = HostUart_LookupConfig(HOST_UART_DEVICE_ID);
	   HostUart_CfgInitialize(&myHostUart, CfgPtr, HostUartConfig_GetBaseAddr(CfgPtr));



}

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=\"SSID\",\"Password\"\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(void){
	u8 command[150];
	u8 finalcmd[50];



	sprintf((char*)command, "GET https://api.thingspeak.com/channels/"ThingSpeak_Channel_Num"/fields/1.json?results=1"
			);



	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(10);
}

void EnableCaches() {
#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_ICACHE
   Xil_ICacheEnable();
#endif
#ifdef XPAR_MICROBLAZE_USE_DCACHE
   Xil_DCacheEnable();
#endif
#endif
}

void DisableCaches() {
#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_ICACHE
   Xil_ICacheDisable();
#endif
#ifdef XPAR_MICROBLAZE_USE_DCACHE
   Xil_DCacheDisable();
#endif
#endif
}

Here is the result from Vitis Serial Terminal. No IPD response and Json Script included. 

AT+CWMODE=3
AT+CWMODE=3

OK
Init Started

AT+CWJAP="ssid","password"
AT+CWJAP="ssid","password"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP

OK
Wifi Done

AT+CIPSTART="TCP","api.thingspeak.com",80
AT+CIPSTART="TCP","api.thingspeak.com",80
CONNECT

OK
Length 71
AT+CIPSEND=71
GET https://api.thingspeak.com/channels/xxxxxxx/fields/1.json?results=1TCPED7


Recv 71 bytes

SEND OK
CLOSED

Meanwhile, I tried the AT command in the Arduino and ESP01S. I can receive the IPD command and Java Script like following:

19:19:52.989 -> AT+CWMODE=3

19:19:52.989 -> 
19:19:52.989 -> OK
19:20:02.336 -> AT+CWJAP="ssid","password"

19:20:02.336 -> WIFI DISCONNECT
19:20:04.486 -> WIFI CONNECTED
19:20:05.468 -> WIFI GOT IP
19:20:07.338 -> 
19:20:07.338 -> OK
19:20:16.096 -> AT+CIPSTART="TCP","184.106.153.149",80

19:20:16.331 -> CONNECT
19:20:16.331 -> 
19:20:16.331 -> OK
19:20:23.943 ->  AT+CIPSEND=69

19:20:23.943 -> 
19:20:23.943 -> OK
19:20:23.943 -> > fields/1.json?results=1

19:20:39.376 -> busy s...
19:20:39.376 -> 
19:20:39.376 -> Recv 69 bytes
19:20:39.611 -> 
19:20:39.611 -> SEND OK
19:20:40.207 -> 
19:20:40.207 -> +IPD,296:{"channel":
{"id":xxxxxxx,"name":"xxxxxxx","latitude":"0.0","longitude":"0.0","field1":"led1","field2":"led2","field3":"led3",
"created_at":"2021-04-30T00:36:29Z","updated_at":"2021-04-30T00:37:05Z","last_entry_id":18},
"feeds":[{"created_at":"2021-06-07T11:13:39Z","entry_id":18,"field1":"0"}]}CLOSED

For updating data from Zybo board to Thingspeak, I can receive the IPD command like following: 

AT+CIPSTART="TCP","api.thingspeak.com",80
AT+CIPSTART="TCP","api.thingspeak.com",80
CONNECT

OK
Length 135
AT+CIPSEND=135
GET http://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxxxx &field1=0.64&field2=29.84&field3=488&field4=47.47&field5=139&field6=6.31
TCPED15

Recv 135 bytes

SEND OK

+IPD,3:420CLOSED

Can anyone tell me how can allow Pmod ESP32 to receive the Java Script like how Arduino does. 

Thanks 

Edited by helloworld1029
Link 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...