wero
November 8, 2017, 11:15am
1
To make a boolean I used a php script to a database that response with 0 or 1,
now I'm trying to use this response to active my buzzer.
I tried for days different things to solve it, but I am not able to get the variable.
Here is the code that send me response in my monitor (1 or 0)
gprsSerial.println("AT+HTTPREAD=0,20");
delay(3000);
toSerial();
So what should I do to put it in a variable or do a condition...
if (gprsSerial.println("AT+HTTPREAD=0,20") == 1) ....
And how long is 0 or 1? (What number should I put here --> AT+HTTPREAD=0,->20<-HERE)
Thanks! I have to release my work in 2 days and this is the last thing to get my project working.
Robin2
November 8, 2017, 3:34pm
2
You need to post the complete program.
...R
wero
November 8, 2017, 4:02pm
3
#include <SoftwareSerial.h>
//#include <TinyGPS.h>
float lat,lon;
SoftwareSerial gprsSerial(7, 8);
//SoftwareSerial gpsSerial(4, 3);
const int buzz = 13;
//TinyGPS gps; // create gps object
void setup()
{
pinMode(buzz, OUTPUT);
gprsSerial.begin(19200);
Serial.begin(19200);
Serial.println("Config SIM900...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
gprsSerial.println("AT+CPIN=\"\"");
delay(25000);
toSerial();
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"youinternet\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"USER\",\"\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"PWD\",\"\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
}
void loop()
{
lat=41.4376106;
lon=2.2249775;
//Check GPRS/GSM available
//while(gpsSerial.available()){
//CSi GPS tiene datos
//if(gps.encode(gpsSerial.read())){
//Recibir datos GPS y establecerlos en variables lat y lon
//gps.get_position(&lat,&lon);
//Print de los datos (Debug)
//TODO eliminar el debug
//Serial.print("Position: ");
//Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
//Serial.print("lon: ");Serial.println(lon); // print longitude
//}
//}
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(3000);
toSerial();
// set http param value
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://foro.battlepvpmine.es/write_data.php?longitude=" + String(lon, 7) + "&latitude=" + String(lat, 7) + "&key=8A621E21A96A6E36\"");
delay(3000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=1");
delay(6000);
toSerial();
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(3000);
gprsSerial.println("");
delay(10000);
///////////////////////////////////////////////
gprsSerial.println("AT+HTTPINIT"); //init the HTTP request
delay(3000);
toSerial();
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://foro.battlepvpmine.es/get_buzzing.php?key=8A621E21A96A6E36\"");// setting the httppara,
//the second parameter is the website from where you want to access data
delay(3000);
toSerial();
gprsSerial.println();
gprsSerial.println("AT+HTTPACTION=0");//submit the GET request
delay(8000);//the delay is important if the return datas are very large, the time required longer.
toSerial();
gprsSerial.println("AT+HTTPREAD=0,20");
delay(6000);
toSound();
/*if(Serial.read().equals("1"))
{
digitalWrite(buzz, HIGH);
Serial.println("Funciona");
}
else
{
digitalWrite(buzz,LOW);
Serial.println("No Funciona");
}
*/
gprsSerial.println("");
delay(3000);
gprsSerial.println("AT+HTTPTERM");// terminate HTTP service
toSerial();
}
void toSound(){
while (gprsSerial.available() != 0 ) {
int a = Serial.write(gprsSerial.println("AT+HTTPREAD=0,20"));
Serial.println("Esto es lo que obtiene: ");
Serial.println(a);
}
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
Robin2
November 8, 2017, 4:29pm
4
To make it easier for people to help you please modify your post and use the code button </> (not the Quote button) so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.
...R
wero
November 8, 2017, 4:33pm
5
The important part is here:
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://foro.battlepvpmine.es/get_buzzing.php?key=8A621E21A96A6E36\"");// setting the httppara,
//the second parameter is the website from where you want to access data
delay(3000);
toSerial();
gprsSerial.println();
gprsSerial.println("AT+HTTPACTION=0");//submit the GET request
gprsSerial.println("AT+HTTPREAD");
delay(3000);
wero
November 8, 2017, 4:40pm
6
I know how to code, the only problem is that I don't know how to get the httpread response into a variable
like...
int x = Serial.read().toInt();
You know?
Robin2
November 8, 2017, 7:44pm
7
What is the point of the toSerial() function? It seems to take all the data and just send it to the Serial Monitor without saving any of it.
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
...R