I have changed some coding based on previous work. However, I always failed to post request to the channel of thingspeak. I have check the channel api key via ''postman'' and its stated that the channel is functioning. I show my coding here and I hope someone could help me to solve this problem. Thank you.

My problem is I dont know how to add in the Api key. I have tried to insert at the coding below. Obviously it is wrong. But, at least the code can run. I would like to know the problem.

 

retcode_t writeNextPartToBuffer(OutMsgSerializationHandover_T* handover)

{

const char url_ptr[100];

int payload;

int n = "api_key=H2XL7UF32O1T2V3Y&field1=1";

uint32_t payloadLength = (uint32_t) strlen(payload);

uint32_t alreadySerialized = handover->offset;

uint32_t remainingLength = payloadLength - alreadySerialized;

uint32_t bytesToCopy;

retcode_t rc;

 

if ( remainingLength <= handover->bufLen ) {

bytesToCopy = remainingLength;

rc = RC_OK;

}

else {

bytesToCopy = handover->bufLen;

rc = RC_MSG_FACTORY_INCOMPLETE;

}

----------------------------------------------------------------------------------------------------------------------------------------------------

Additionally, I have insert the website at this code.

void createAndSendPostMessage(void){

// assemble the request message

Ip_Address_T destAddr;

NetworkConfig_GetIpAddress((uint32_t) "api.thingspeak.com/update.json", &destAddr);

Ip_Port_T port = Ip_convertIntToPort(80);

 

Msg_T* msg_ptr;

HttpClient_initRequest(&destAddr, port, &msg_ptr);

HttpMsg_setReqMethod(msg_ptr, Http_Method_Post);

HttpMsg_setReqUrl(msg_ptr, "/post");

 

Msg_prependPartFactory(msg_ptr, &writeNextPartToBuffer);

 

// send the request

static Callable_T sentCallable;

Callable_assign(&sentCallable, &onHTTPRequestSent);

HttpClient_pushRequest(msg_ptr, &sentCallable, &onHTTPResponseReceived);

}

0 (0 Stimmen)
RE: HTTP Post Request to Matlab Thingspeak
Antwort
03.04.19 08:41 als Antwort auf l Kent.

Hi

Please refer this post for more information

https://xdk.bosch-connectivity.com/community/-/message_boards/message/481232

thanks

Santhosh babu

 

0 (0 Stimmen)