Data not show in thingspeak using sim800l
5 ビュー (過去 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!

