Hello Guys,
starter coder here.
I’m using a Arduino Mega 2560 with a SIM900 Shield, to send/post some text in a webserver.
I already tested the hardware to send SMS ans calls, and everything works fine.
But now I’m trying to post some text/string in to a webserver. I’m using 000webhost.com as server, and created a database in it.
The code works this way. Using any mobile phone, i send some SMS text to SIM900 shield, and as soon as it detects this new SMS, it sends this same content to the webserver.
I was using a 2015 tutorial to help me.
Did the PHP files, with user, login, etc.
used the inet.httpPOST() to uploa the information.
Arduino connects, receives the SMS and starts connection with DB. But nothing is being posted.
My strugle is with this PHP files and DB settings.
I attached the PHP files and C code along with the serial monitor messages.
Please, help me out!
#include <SoftwareSerial.h>
#include "inetGSM.h"
InetGSM inet;
boolean started = false;
char smsbuffer[160];
char n[20];
byte valor;
void setup()
{
Serial.begin(9600);
powerUpOrDown();
Serial.println(F("Testando GSM Shield SIM900"));
if (gsm.begin(2400))
{
Serial.println(F("\nstatus=READY"));
started = true;
}
else Serial.println(F("\nstatus=IDLE"));
}
void loop()
{
if (started) {
//Aguarda novo SMS e envia para o servidor web
if (gsm.readSMS(smsbuffer, 160, n, 20)) {
String str(smsbuffer);
envia_GSM(smsbuffer);
delay(10000);
}
delay(1000);
}
}
void powerUpOrDown()
{
//Liga o GSM Shield
Serial.print(F("Liga GSM..."));
pinMode(6, OUTPUT);
digitalWrite(6, LOW);
delay(1000);
digitalWrite(6, HIGH);
delay(1000);
Serial.println(F("OK!"));
digitalWrite(6, LOW);
delay(500);
}
void envia_GSM(String texto)
{
char temp_string[55];
char msg[10];
int numdata;
if (inet.attachGPRS("zap.vivo.com.br", "vivo", "vivo"))
Serial.println(F("status=Conectado..."));
else Serial.println(F("status=Nao conectado !!"));
delay(100);
String valor = "MSG_Texto1=" + texto;
valor.toCharArray(temp_string, 55);
numdata = inet.httpPOST("autoformula.000webhostapp.com", 80, "/add.php", temp_string, msg, 50);
delay(5000);
}
Serial Monitor
Liga GSM...OK!
Testando GSM Shield SIM900
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:ELSE
ATT: OK
RIC: AT
OK
DB:CORRECT BR
ATT: OK
RIC: AT
OK
ATT: OK
RIC: AT&F
OK
ATT: OK
RIC: ATE0
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: OK
RIC:
OK
ATT: +CPMS:
RIC:
+CPMS: 2,30,2,30,2,30
OK
ATT: OK
RIC:
OK
ATT: SHUT OK
RIC:
SHUT OK
status=READY
This method is deprecated! Please use GetSMS in the SMS class.
ATT: +CMGL
RIC: ⸮
+CMGL: 1,"REC UNREAD","+5511972198314","","18/10/22,09:38:02-12"
Hey
OK
⸮
ATT: OK
RIC:
OK
ATT: ERROR
RIC:
100.99.92.209
DB:ALREADY HAVE AN IP
ATT: ERROR
RIC:
ERROR
status=Conectado...
ATT: OK
RIC:
OK
⸮
DB:RECVD CMD
ATT: CONNECT OK
RIC:
OK
⸮
ATT: OK
RIC: ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
DB:NOT CONN
ATT: OK
RIC:
ERROR
ALREADY CONNECT
DB:NOT CONN
ATT: OK
RIC: ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
ERROR
ALREADY CONNECT
CONNECT OK
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
DB:RECVD CMD
ATT: CONNECT OK
RIC: ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
ERROR
ALREADY CONNECT
CONNECT OK
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
DB:OK TCP
ATT: >
RIC:
>
DB:>
ATT: SEND OK
add.php.txt (354 Bytes)
connect.php.txt (412 Bytes)
index.php.txt (1.14 KB)