118 lines
5.2 KiB
C
118 lines
5.2 KiB
C
|
#include "user_http.h"
|
|||
|
#include <stdlib.h>
|
|||
|
#include "cjson.h"
|
|||
|
#include "userapp.h"
|
|||
|
#include "key.h"
|
|||
|
#include "user_flash.h"
|
|||
|
#include "user_tcp.h"
|
|||
|
#include "rtc.h"
|
|||
|
|
|||
|
/********************************************************************************
|
|||
|
* @file gate_http.c
|
|||
|
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
|
|||
|
* @version V1.0.0
|
|||
|
* @date 11-Dec-2018
|
|||
|
* @brief <EFBFBD>ṩQuectelģ<EFBFBD><EFBFBD>EC20<EFBFBD><EFBFBD><EFBFBD><EFBFBD>HTTP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
******************************************************************************
|
|||
|
* @attention
|
|||
|
*
|
|||
|
* Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* contextID:<EFBFBD><EFBFBD>·ID connetcID<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ID channal<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
* EC20ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·ID<EFBFBD><EFBFBD>Χ1~16<EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·ID<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD> ͨ<EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>Χ0~11<EFBFBD><EFBFBD>
|
|||
|
* ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·ID<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>12<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ƹ涨<EFBFBD><EFBFBD>HTTPЭ<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·1D<EFBFBD><EFBFBD><EFBFBD><EFBFBD>contextID=2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HTTP<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>
|
|||
|
* @use<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>Http_Init()<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>HTTP<EFBFBD><EFBFBD>·<EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>Send_Post<EFBFBD><EFBFBD><EFBFBD><EFBFBD>POST<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>Http_Read<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>POST<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
|
|||
|
/*****************************************
|
|||
|
*<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
****************************************/
|
|||
|
/*Ӳ<><D3B2>ע<EFBFBD><D7A2><EFBFBD>ӿ<EFBFBD> post<73><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD>궨<EFBFBD><EAB6A8>*/
|
|||
|
#define REG_BUF "POST http://%s%s HTTP/1.1\r\nContent-Type:application/json;charset=UTF-8\r\nHost:%s\r\ncontent-length:%d\r\n\r\n%s" //ע<><D7A2><EFBFBD>ӿڵ<D3BF><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#define REG_HOST "quan.suning.com" //ע<><D7A2><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD>ӿ<EFBFBD>
|
|||
|
#define REG_PORT "/getSysTime.do" //ע<><D7A2><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>
|
|||
|
#define REC_BODY "{\"mac\":\"%s\"}" //body:{\"mac\":\"31FFD305524E353723892251\"}
|
|||
|
|
|||
|
|
|||
|
/***************postBuf**********host***********httpPort**********body***************/
|
|||
|
POSTP_s sReg = {REG_BUF, REG_HOST, REG_PORT, REC_BODY} ; //ע<><D7A2><EFBFBD>ӿڵ<D3BF>POSTP_sʵ<73><CAB5><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/*********************************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>RunResult Reg_Post(void)
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD>reg<EFBFBD>ӿ<EFBFBD><EFBFBD>ύPOST<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD>ע<EFBFBD>ᣬͬ<EFBFBD><EFBFBD>RTCʱ<EFBFBD>䡢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* 1<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>POST<EFBFBD><EFBFBD><EFBFBD><EFBFBD>body:
|
|||
|
* REC_BODY "{"mac":"31FFD305524E353723892251"}"
|
|||
|
* 2<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>POST<EFBFBD><EFBFBD><EFBFBD><EFBFBD>JSON:
|
|||
|
* "{"sysTime2":"2020-10-10 10:58:44","sysTime1":"20201010105844"}"
|
|||
|
* ע <EFBFBD>⣺ <EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD>ӿڲ<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>κ<EFBFBD>body<EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD>MAC<EFBFBD><EFBFBD>json<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>body<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ģ<EFBFBD>
|
|||
|
* 1<EFBFBD><EFBFBD>http<EFBFBD><EFBFBD>josn<EFBFBD>ܳ<EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>cjson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>json<EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>
|
|||
|
*********************************************************************************************************************/
|
|||
|
RunResult Reg_Post(void)
|
|||
|
{
|
|||
|
RunResult runResult = TIMEOUT ;
|
|||
|
GetDeviceMacAddress((uint8_t*)gateApp.macId, STRMACID) ;
|
|||
|
|
|||
|
cJSON * regBody = 0 ; //<2F><><EFBFBD><EFBFBD>cjson
|
|||
|
char * regBodyStr = 0 ; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>cjson<6F><6E><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
regBody = cJSON_CreateObject(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cJSON_AddStringToObject(regBody, "mac", (const char*)gateApp.macId); //<2F><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
regBodyStr=cJSON_Print(regBody);
|
|||
|
|
|||
|
DebugLogPrintf("Ӳ<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>JSON<EFBFBD><EFBFBD>%s", regBodyStr);
|
|||
|
runResult = Send_Post( &sReg, regBodyStr) ;
|
|||
|
if(runResult == RUNOK ) //post<73><74><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|||
|
{
|
|||
|
runResult = Http_Read() ; //<2F><>ȡpost<73><74><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if( RUNOK == runResult ) //<2F><>ȡPOST<53><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>
|
|||
|
{
|
|||
|
cJSON *json=NULL, *json_time=NULL; //json<6F><6E>json<6F><6E><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>,json_time<6D><65> sysTime2<65><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
json = cJSON_Parse((const char*)strrchr(ec20HttpBuf, '{')); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
|||
|
if (NULL == json) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
{
|
|||
|
AppLogPrintf("cjson err:%s", cJSON_GetErrorPtr()) ;
|
|||
|
runResult = RUNERR ;
|
|||
|
}
|
|||
|
else //<2F><><EFBFBD><EFBFBD>json<6F>ɹ<EFBFBD>
|
|||
|
{
|
|||
|
json_time = cJSON_GetObjectItem(json, "sysTime2") ; //<2F><><EFBFBD>ҡ<EFBFBD>sysTime2<65><32><EFBFBD>ֶ<EFBFBD>
|
|||
|
if( (json_time != NULL) && (json_time->type == cJSON_String)) /*<2A><><EFBFBD>ڡ<EFBFBD>sysTime2<65><32><EFBFBD>ֶ<EFBFBD>*/
|
|||
|
{
|
|||
|
strncpy( (char*)uCalendar.bytes, json_time->valuestring, 19) ;
|
|||
|
RTC_Set( &uCalendar ) ; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
Calendar_u uAlaCal ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
memcpy(uAlaCal.bytes, uCalendar.bytes, CALENDAR_LEN) ;
|
|||
|
uAlaCal.sCalendar.w_date[1] += 1 ; //<2F><><EFBFBD><EFBFBD>+1<><31>
|
|||
|
memcpy((u8*)uAlaCal.sCalendar.hour, "01", 2) ; //<2F>賿1<E8B3BF><31> <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ڴ˿̵<CBBF>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ
|
|||
|
//memcpy((u8*)uAlaCal.sCalendar.min, "48", 2) ; //<2F>賿30<33><30>//uAlaCal.sCalendar.sec[0] += 2 ;
|
|||
|
RTC_Alarm_Set(&uAlaCal) ;
|
|||
|
DebugLogPrintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺%s\n", json_time->valuestring);
|
|||
|
}
|
|||
|
else /*<2A><><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>sysTime2<65><32><EFBFBD>ֶ<EFBFBD>*/
|
|||
|
{
|
|||
|
runResult = RUNERR ;
|
|||
|
ErrorLogPrintf("No \"json_time\" .") ;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
cJSON_Delete(json); //<2F>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|||
|
}
|
|||
|
else //<2F><>ȡPOST<53><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
else //POST<53><54><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
{
|
|||
|
HTTPBIT_3 = false ;
|
|||
|
}
|
|||
|
cJSON_Delete(regBody) ;
|
|||
|
return runResult ;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|