Hi to all
i have the code bellow that works fine until the line GET command that gives me an error in serial monitor and no data is written to the Mysql
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9); // RX, TX
const byte simStart = 12;
int humidityData = 69;
int temperatureData = 78;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(9600);
pinMode(12, INPUT_PULLUP);
}
void loop() {
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
if (digitalRead(simStart) == LOW) {
GSMconnection();
}
else if (digitalRead(simStart) == HIGH) {
}
}
void GSMconnection()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("Connecting");
delay(2000);
Serial.println("Done!...");
mySerial.flush();
Serial.flush();
// See if the SIM800 is ready
mySerial.println("AT");
delay(1000);
ReadSerial();
// SIM card inserted and unlocked?
mySerial.println("AT+CPIN?");
delay(1000);
ReadSerial();
// Is the SIM card registered?
mySerial.println("AT+CREG?");
delay(1000);
ReadSerial();
// Is GPRS attached?
mySerial.println("AT+CGATT?");
delay(1000);
ReadSerial();
// Check signal strength
mySerial.println("AT+CSQ ");
delay(1000);
ReadSerial();
// Set connection type to GPRS
mySerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(2000);
ReadSerial();
// Set the APN
mySerial.println("AT+SAPBR=3,1,\"APN\",\"APN_name_Here\"");
delay(2000);
ReadSerial();
// Enable GPRS
mySerial.println("AT+SAPBR=1,1");
delay(10000);
ReadSerial();
// Check to see if connection is correct and get your IP address
mySerial.println("AT+SAPBR=2,1");
delay(2000);
ReadSerial();
Sending_To_phpmyadmindatabase();
}
void Sending_To_phpmyadmindatabase() //CONNECTING WITH MYSQL
{
// initialize http service
mySerial.println("AT+HTTPINIT");
delay(2000);
ReadSerial();
mySerial.println("AT+HTTPPARA=\"CID\",1");
delay(2000);
ReadSerial();
// set http param value
mySerial.println("AT + HTTPPARA = \"URL\",\"www.myWeb.address/test.php\"");
delay(4000);
ReadSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
mySerial.println("AT+HTTPACTION=0");
delay(6000);
ReadSerial();
// Make a HTTP request:
Serial.print("GET /test.php?humidity=");
mySerial.print("GET /test.php?humidity="); //YOUR URL
Serial.println(humidityData);
mySerial.print(humidityData);
mySerial.print("&temperature=");
Serial.println("&temperature=");
mySerial.print(temperatureData);
Serial.println(temperatureData);
mySerial.print(" "); //SPACE BEFORE HTTP/1.1
mySerial.print("HTTP/1.1");
mySerial.println();
delay(1000);
mySerial.println("AT+HTTPTERM");
delay(1000);
ReadSerial();
//close connection
mySerial.println("AT+SAPBR=0,1");
delay(2000);
ReadSerial();
mySerial.println();
}
void ReadSerial()
{
while (mySerial.available() != 0)
{
Serial.write(mySerial.read());
}
}
here is the serial monitor print :
(i have changed only my personal info (apn real name, web address etc)
Connecting
Done!...
AT
OK
AT+CPIN?
+CPIN: READY
OK
AT+CREG?
+CREG: 0,5
OK
AT+CGATT?
+CGATT: 1
OK
AT+CSQ
+CSQ: 19,0
OK
AT+SAPBR=3,1,"Contype","GPRS"
OK
AT+SAPBR=3,1,"APN","APN_name_Here"
OK
AT+SAPBR=1,1
⸮⸮
OK
AT+SAPBR=2,1
+SAPBR: 1,1,"10.140.225.41"
OK
AT+HTTPINIT
OK
⸮⸮⸮⸮AT+HTTPPARA="CID",1
OK
AT + HTTPPARA = "URL","www.myWeb.address/test.php"
AT+HTTPACTION=0
OK
⸮⸮
+HTTPACTION: 0,200,1
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮connected
GET /mpersefoni001.php?humidity=69
&temperature=
78
GET /test.php?humidity=69&temperature=78 HTTP/1.1
ERROR
AT+SAPBR=0,1
⸮⸮
OK
Here is the php script with test.php name in my server (it is not my code as i dont know anything about php coding , but i can ensure you that works fine when i run it in my browser and put manual the data. it updates my Mysql table
example : http://www.myWeb.address/test.php?humidity=65&temperature=41 )
<?php
class dht11{
public $link='';
function __construct($temperature, $humidity){
$this->connect();
$this->storeInDB($temperature, $humidity);
}
function connect(){
$this->link = mysqli_connect('localhost','My_user','My_Password') or die('Cannot connect to the DB');
mysqli_select_db($this->link,'<Your Database Name>') or die('Cannot select the DB');
}
function storeInDB($temperature, $humidity){
$query = "insert into <Your table name> set humidity='".$humidity."', temperature='".$temperature."'";
$result = mysqli_query($this->link,$query) or die('Errant query: '.$query);
}
}
if($_GET['temperature'] != '' and $_GET['humidity'] != ''){
$dht11=new dht11($_GET['temperature'],$_GET['humidity']);
}
?>