Data not show in thingspeak using sim800l
조회 수: 16 (최근 30일)
이전 댓글 표시
I'm using sim800l and arduino uno for monitoring battery. The code has no error, but data not show in thingspeak. this is the code:
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial SIM800L(6,7); //Serial SIM800L pin
String Write_API_key = "xxxxxxxxxxxxxxxx"; //Thingspeak Write API Key
String apn = "internet";
int analogPin = A0; // pin arduino yang terhubung dengan pin S modul sensor tegangan
float Vmodul = 0.0;
float hasil = 0.0;
float R1 = 10000.0; //10k
float R2 = 220.0; //220 ohm resistor,
float value = 0.0;
int persen = 0;
void setup(){
Serial.begin(115200);
SIM800L.begin(9600);
pinMode(analogPin,INPUT);
Serial.println("SIM800L GPRS Test");
delay(2000);
}
void loop(){
SetupModule();
SIM800L.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");
delay(3000);
ShowSerialData();
SIM800L.println("AT+CIPSEND");
delay(2000);
Serial.println();
ShowSerialData();
ReadSensor();
String str="GET https://api.thingspeak.com/update?api_key="+Write_API_key+"&field1=" + String(hasil) +"&field2="+String(persen);
Serial.println(str); delay(2000);
SIM800L.println(str); delay(4000);
ShowSerialData();
SIM800L.println((char)26); delay(4000);
SIM800L.println();
ShowSerialData();
SIM800L.println("AT+CIPSHUT");//close the connection
delay(500);
ShowSerialData();
str="";
//total delay looping 50s
delay(10000); //add 10s for 60s total delay looping
}
void ReadSensor(){
value = analogRead(analogPin);
Vmodul = (value * 5) / 1024.0;
hasil = Vmodul / (R2/(R1+R2));
persen = (hasil/60)*100;
Serial.print("\t Tegangan Pembagi = ");
Serial.print(Vmodul,2);
Serial.print("volt");
Serial.print("\t Hasil pengukuran asli = ");
Serial.print(hasil,1);
Serial.println("volt");
Serial.print("\t Persentase baterai = ");
Serial.print(persen);
Serial.println("%");
}
void SetupModule(){
if (SIM800L.available())Serial.write(SIM800L.read());
SIM800L.println("AT"); delay(1000);
SIM800L.println("AT+CPIN?"); delay(1000);
SIM800L.println("AT+CREG?"); delay(1000);
SIM800L.println("AT+CGATT?"); delay(1000);
SIM800L.println("AT+CIPSHUT");delay(1000);
SIM800L.println("AT+CIPSTATUS"); delay(2000);
SIM800L.println("AT+CIPMUX=0"); delay(2000);
//setting the APN,
SIM800L.println("AT+CSTT=\""+apn+"\"");delay(1000);
ShowSerialData();
SIM800L.println("AT+CIICR"); delay(2000);
ShowSerialData();
//get local IP adress
SIM800L.println("AT+CIFSR"); delay(2000);
ShowSerialData();
SIM800L.println("AT+CIPSPRT=0");delay(2000);
ShowSerialData();
}
void ShowSerialData(){
while(SIM800L.available()!=0)
Serial.write(SIM800L.read());
delay(2000);
}
댓글 수: 0
답변 (2개)
Christopher Stapels
2022년 6월 1일
Here is a sim 800l example, that the autor says is working. Can you compare to that one and see what is different? There should be something in the serial monitor that indicated what the device is doing.
You might try hard codng a value to write to ThingSpeak (in place of String(hasil)), just to make sure there isnt a problem with your sensor.
댓글 수: 5
Christopher Stapels
2022년 6월 1일
They also mention using
gprsSerial.println("AT+CSTT=\"internet\"")
which seems different than your APN setting. Ive not used the Sim module, but could this be the issue?
Christopher Stapels
2022년 6월 1일
How about adding Serial.println("<description>") each time you write to the sim card? Then you can make sure everything is being executed.
댓글 수: 0
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

