Hello Everyone,
I am working on an IoT-based project, Since I have somewhat achieved what the device(Arduino Uno, DHT 11, and Sim 900a ) is intended to do, I now need to run the device on a power supply, Meaning I won't be able to open the Serial Monitor Through my laptop, and as a result, I suspect the code won't work, because the Serial Buffer will be full and the code won't process further. Can you guys give me any suggestions, I have tried searching the internet but I could not find anything satisfactory.
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(2,3);
#include "EmonLib.h"
#include <String.h>
#include <DHT.h>
#define DHTPIN A0
EnergyMonitor emon1;
DHT dht(DHTPIN, DHT11);
void setup()
{
gprsSerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
dht.begin();
emon1.current(1, 111.1);
delay(1000);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
double Irms = emon1.calcIrms(1480);
delay(100);
Serial.print("Temperature = ");
Serial.print(t);
Serial.println(" °C");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println(" %");
Serial.println(Irms);
Serial.println("Ampere");
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=\"ufone.pinternet\"");//start task and setting the APN,
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="GET https://api.thingspeak.com/update?api_key=MG7I0XOD86XQEPXJ&field1=" + String(t) +"&field2="+String(h)+"&field3="+String(Irms);
Serial.println(str);
gprsSerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();
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);
}