Data not show in thingspeak using sim800l

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);
}

Risposte (2)

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 Commenti

sorry but still not working. this the serial monitor just show like this
the thingspeak just show like this. the data displayed is the data that I entered manually (i copy the link in serial monitor to browser and i just refresh the thingspeak view)
That is a good test, im glad you tried the browser version. Also thanks for the serial output. Did you compare your code to the working example that I linked? Do you see any differences?
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?
i try the code that you linked but not working. the sim card i use has apn settings "internet" to.

Accedi per commentare.

How about adding Serial.println("<description>") each time you write to the sim card? Then you can make sure everything is being executed.

Community

Più risposte nel  ThingSpeak Community

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by