Can't send data to thingspeak api using GET HTTP

조회 수: 10 (최근 30일)
joem
joem 2019년 10월 11일
답변: Vinod 2019년 10월 21일
I build an arduino based device and connect a GSM900 module to it which can establish GPRS connection and visit website. Also I have created an account in thingspeak. I tested sending data to the field with the browser in my PC by visiting https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=0, and it does upload data and shows a number.
But when I try to do the same thing with the arduino based device, after
It dosn't repond nor shows the number. Is there anything missing?
The following is the arduino sketch and all the at command before the line above shows "ok" result.
Also, is there a way to test this GSM900 module is able to get http?
#include <SoftwareSerial.h>
SoftwareSerial softSerial(51, 52);//
void setup() {
Serial.begin(9600);
softSerial.begin(9600);
Serial.println("Initing...please wait.");
softSerial.println("AT+CPIN?");
delay(500);
printLine();
softSerial.println("AT+CGATT?");
delay(500);
printLine();
softSerial.println("AT+CIPSHUT");
delay(500);
printLine();
softSerial.println("AT+CIPSTATUS");
delay(500);
printLine();
softSerial.println("AT+CIPMUX=0");
delay(500);
printLine();
softSerial.println("AT+CSTT=\"ZENNET\"");
delay(500);
printLine();
softSerial.println("AT+CIICR");
delay(3000);
printLine();
softSerial.println("AT+CIFSR");
delay(1000);
printLine();
//softSerial.println("AT+CIPSPRT=0");
// delay(1000);
// printLine();
softSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");
//AT+CIPSTART="TCP","api.thingspeak.com","80"
delay(3000);
printLine();
softSerial.println("AT+CIPSEND");
delay(13000);
printLine();
softSerial.println("GET https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=0");
delay(20000);
printLine();
softSerial.println("\#026");
delay(3000);
printLine();
softSerial.println("AT+CIPSHUT");
delay(500);
printLine();
}
void loop() {
}
void printLine() {
String data;
while (softSerial.available() > 0)
{
char c = softSerial.read();
data += c;
}
Serial.println(data);
}

답변 (1개)

Vinod
Vinod 2019년 10월 21일
Have you tried using the ThingSpeak library: https://github.com/mathworks/thingspeak-arduino
I'd recommend starting with those examples as a reference.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 ThingSpeak에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by