Send Bulk json data with SIM 900 POST request | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Send Bulk json data with SIM 900 POST request
No permission to create posts
May 6, 2018
8:19 am
Avatar
el_poba
New Member
Members
Forum Posts: 2
Member Since:
May 6, 2018
sp_UserOfflineSmall Offline

Hello Everyone,

For my project i have to send some data of my sensors to my Thing Spek chanell by arduino and SIM 900.
I tryed to send one data with GET request and everithing is ok, the channel's Entries increases. The problem is when i try to import json data with POST request.
Nothing happen, the counter is still fixed and the data don't update in my channel.

*--------------------------------------------------*
This is my code:

#include
/* Create object named SIM900 of the class SoftwareSerial */
SoftwareSerial SIM900(7, 8);

char data[500] = "{\"write_api_key\":\"my write api key\",\"updates\":[{\"2018-05-01-18:22:22-0500\":0,\"field1\":60}]}"; //data json to send

void setup() {
SIM900.begin(9600); /* Define baud rate for software serial communication */
Serial.begin(9600); /* Define baud rate for serial communication */
}

void loop() {

Serial.println("HTTP post method :");
Serial.print("AT\
\
");
SIM900.println("AT"); /* Check Communication */
delay(5000);
ShowSerialData(); /* Print response on the serial monitor */
delay(5000);
/* Configure bearer profile 1 */
Serial.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\
\
");
SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""); /* Connection type GPRS */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+SAPBR=3,1,\"APN\",\"internet.wind\"\
\
");
SIM900.println("AT+SAPBR=3,1,\"APN\",\"internet.wind\""); /* APN of the provider */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+SAPBR=1,1\
\
");
SIM900.println("AT+SAPBR=1,1"); /* Open GPRS context */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+SAPBR=2,1\
\
");
SIM900.println("AT+SAPBR=2,1"); /* Query the GPRS context */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPINIT\
\
");
SIM900.println("AT+HTTPINIT"); /* Initialize HTTP service */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPPARA=\"CID\",1\
\
");
SIM900.println("AT+HTTPPARA=\"CID\",1"); /* Set parameters for HTTP session */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPPARA=\"URL\",\"api.thingspeak.com/channels/my channel ID/bulk_update.json\"\
\
");
SIM900.println("AT+HTTPPARA=\"URL\",\"api.thingspeak.com/channels/my channel ID/bulk_update.json\""); /* Set parameters for HTTP session */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPPARA=\"CONTENT\",\"application/json\"\
\
");
SIM900.println("AT+HTTPPARA=\"CONTENT\",\"application/json\""); /* Set CONTENT Type */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPPARA=\"UA\",\"mw.doc.bulk-update\"\
\
");
SIM900.println("AT+HTTPPARA=\"UA\",\"mw.doc.bulk-update\"");
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPDATA=33,10000\
\
");
SIM900.println("AT+HTTPDATA=33,10000"); /* POST data of size 33 Bytes with maximum latency time of 10seconds for inputting the data*/
delay(2000);
ShowSerialData();
delay(2000);

Serial.print(data); /* Data to be sent */
SIM900.println(data);
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPACTION=1\
\
");
SIM900.println("AT+HTTPACTION=1"); /* Start POST session */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPTERM\
\
");
SIM900.println("AT+HTTPTERM"); /* Terminate HTTP service */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+SAPBR=0,1\
\
");
SIM900.println("AT+SAPBR=0,1"); /* Close GPRS context */
delay(5000);
ShowSerialData();
delay(5000);
}

*----------------------------------------------------*
This is my response from various requests from serial port:

HTTP post method :
AT
AT

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","internet.wind"
AT+SAPBR=3,1,"APN","internet.wind"

OK
AT+SAPBR=1,1
AT+SAPBR=1,1

OK
AT+SAPBR=2,1
AT+SAPBR=2,1

+SAPBR: 1,1,"10.68.74.90"

OK
AT+HTTPINIT
AT+HTTPINIT

OK
AT+HTTPPARA="CID",1
AT+HTTPPARA="CID",1

OK
AT+HTTPPARA="URL","api.thingspeak.com/channels/MYCHANNELID/bulk_update.json"
AT+HTTPPARA="URL","api.thingspeak.com/channels/MYCHANNELID/bulk_updaAT+HTTPPARA="CONTENT","application/json"
AT+HTTPPARA="CONTENT","application/json"

OK
AT+HTTPPARA="UA","mw.doc.bulk-update"
AT+HTTPPARA="UA","mw.doc.bulk-update"

OK
AT+HTTPDATA=33,10000
AT+HTTPDATA=33,10000

DOWNLOAD
{"write_api_key":"MY WRITE API_KEY","updates":[{"2018-05-01-18:22:22-0500":0,"field1":60}]}
OK
AT+HTTPACTION=1
AT+HTTPACTION=1

OK

+HTTPACTION:1,401,154
AT+HTTPTERM
AT+HTTPTERM

OK

*-----------------------------------------------------------*

Thank to Those taht will wont support me,

Francesco P.

May 7, 2018
9:46 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 258
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Do you need to update multiple entries at once? You are using the bulk update endpoint, which is more complex than the normal update. Here is the doc nor a normal write data operation.
https://www.mathworks.com/help/thingspeak/writedata.html

If you want to update a lot of feeds at once, you will need the bulk update. If this is the case, I would start by looking at the date format, I think there my be an extra dash in your date:
"2018-05-01-18:22:22-0500":0,"field1":60"

Did you replace "your channel id" in the code above? I assume you did for that and api keys.

Last, I would recount the bytes. I think you are sending more than 33 bytes (I got near 102).
Let us know how it goes, it would be good to have some standard code for AT command data entry.

May 12, 2018
9:50 am
Avatar
el_poba
New Member
Members
Forum Posts: 2
Member Since:
May 6, 2018
sp_UserOfflineSmall Offline

Thank you for your consideration.

Yes i need to send all data just once a day for safe my energy batteries.
Yes i replaced my channel ID and my API Key to the appropriate part of the code.
I tried to increase the data size but nothing appened.
Finlly, I think the problems are in the data string. I have to get a corretc array to send.
At the moment with my Knowledge this is little bit difficult...

May 15, 2018
9:57 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 258
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Some of these small devices have a limited memory buffer, so I recommend sending many small parts of your bulk update string instead of sending it all at once, once your sting gets larger.

You might try using the data in the documentation example, just to practice the syntax, since the format can be tricky. https://www.mathworks.com/help/thingspeak/bulkwritejsondata.html

One thing you missed in the format is the time format specifier. You need "created_at" or "delta_t". Have a look closely at the format in the doc.
updates":[{"2018-05-01-18:22:22-0500":0,"field1":60}]}

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
37 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

GenriWat, augustarp2, eduardohr18, Rufusdok, nellievd4, susannaab1

Administrators: Hans: 387, lee: 457