How to implement a "bulk-update" using AT commands and POST Method | Arduino | 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
How to implement a "bulk-update" using AT commands and POST Method
No permission to create posts
September 8, 2020
8:11 pm
Avatar
lucasnetog
New Member
Members
Forum Posts: 1
Member Since:
September 8, 2020
sp_UserOfflineSmall Offline

Hello everyone!
I am trying to send multiple entries to my channel but I am stuck.
I am using an Arduino Uno plus a SIM900 shield. I changed the code a lot and this version is the closest to a functional one because this one I can access the Thingspeak Server and I got a response: Error 400 Bad Gateway.

This is my code:

#include
SoftwareSerial gprsSerial(7,8);

#include

String data = "{\"write_api_key\": \"XXXXXXXXXXXXXXXX\",\"updates\": [{\"created_at\":\"2020-09-04 14:10:00 -0500\",\"field1\": 10,\"field2\":92}, {\"created_at\":\"2020-09-04 14:20:00 -0500\",\"field1\": 12,\"field2\":93}]}";

void setup()
{
gprsSerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
delay(1000);
}

void loop()
{
if (gprsSerial.available())
Serial.write(gprsSerial.read());

gprsSerial.println("AT");
delay(1000);

gprsSerial.println("AT+CPIN?");
delay(1000);

gprsSerial.println("AT+CREG?");
delay(1000);

gprsSerial.println("AT+CGATT?");
delay(1000);

gprsSerial.println("AT+CIPSHUT");
delay(1000);

gprsSerial.println("AT+CIPSTATUS");
delay(2000);

gprsSerial.println("AT+CIPMUX=0");
delay(2000);

ShowSerialData();

gprsSerial.println("AT+CSTT=\" gprs.oi.com.br \"");//start task and setting the APN from my country
delay(1000);

ShowSerialData();

gprsSerial.println("AT+CIICR");//bring up wireless connection
delay(3000);

ShowSerialData();

gprsSerial.println("AT+CIFSR");//get local IP adress
delay(2000);

ShowSerialData();

gprsSerial.println("AT+CIPSPRT=0");
delay(3000);

ShowSerialData();

gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);

ShowSerialData();

gprsSerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();

String str="POST api.thingspeak.com/update.json"; // I tried here many many URLS and i dont know how to make this POST request work
Serial.println(str);
gprsSerial.println(str);//begin send data to remote server
delay(1000);

Serial.println("Content-Type:application/json");
gprsSerial.print("Content-Type:application/json");
delay(1000);

Serial.println(data); // data is the string that I had declared and it is on a Json format. I tested using a POST test website and I got it to Thingspeak ( 5 entries)
gprsSerial.println(data);
delay(1000);

gprsSerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
gprsSerial.println();

ShowSerialData();

gprsSerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}

void ShowSerialData()
{
while(gprsSerial.available()!=0)
Serial.write(gprsSerial.read());
delay(5000);

}

September 17, 2020
2:14 pm
Avatar
cstapels
Moderator
Members


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

I would start with POSTMAN and make sure you have the syntax correct for your POST first.
There is a good example in the bulk update doc.

FYI, MATLAB answers is the preferred location for ThingSpeak Community support.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
23 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

anis, 43994554AKS, suda, marisol, qkpham, SANGAMNATH B

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457