|
C語言定義長整型變量unsigned long count=123456;
我想通過串口,將這個變量上傳服務器,請問如何將這個long變量轉成字符串通過串口發送呢,程序中發送命令在POST(),請各位大神幫忙看看。
void POST(void)//POST數據函數
{
int dataLen;
uchar postData[150];
char strLen[3];
char strtemp[20];
sprintf(strtemp,"%d",count);
sprintf(postData,"uid=%s&topic=%s&msg=#%0x#\r\n",Uid,Topic,strtemp);
dataLen = strlen(postData); //計算數據長度
sprintf(strLen,"%d",dataLen); //int類型轉char
ESP8266_Set("AT+CIPMODE=1"); //開啟透明傳輸模式
ms_delay(1000);
ESP8266_Set("AT+CIPSTART=\"TCP\",\"api.bemfa點com\",80"); // 連接服務器和端口
ms_delay(1000);
ESP8266_Set("AT+CIPSEND"); //進入透傳模式,下面發的都會無條件傳輸
ms_delay(1000);
ESP8266_Set_Only("POST /api/device/v1/data/1/ HTTP/1.1\r\nHost: api.bemfa點com\r\nContent-Type: application/x-www-form- urlencoded\r\nConnection:close\r\nContent-Length:");//??device? ??sensor?
ESP8266_Set(strLen);//數據長度(postData數據長度),一定要準確
ESP8266_Set("");//回車(發完數據長度后,有回車,不懂的百度http post 格式)
ESP8266_Set(postData);//發送數據
ms_delay(2000);
ESP8266_Set("+++"); //
memset(strLen,'\0',3); //重置數組
memset(postData,'\0',sizeof postData);//重置數組
}
|
|