Prezados,
Este projeto consiste em receber mensagens e armazená-las em um banco de dados localizado no servidor gratuito
www.000webhost.com. Ele foi baseado no
Tutorial da Arduino e Cia:como acessar a internet com o Arduino GSM Shield SIM900. Segue o link abaixo:
http://www.arduinoecia.com.br/2015/11/acessar-internet-arduino-gsm-shield-sim-900.htmlÉ um artigo bastante didático. Porém devido o mesmo ser de 2015, foi necessário fazer algumas pequenas adaptações, principalmente no código das páginas em PHP.
O problema é que o Arduino (estou usando o arduino Mega 2560) não está conseguindo enviar a mensagem para ser gravada no banco de dados. Seguem abaixo as mensagens do monitor serial do arduino e os códigos usados no arduino e páginas PHP.
Gostaria dos colegas para identificar onde está a falha.
Desde já agradeço a atenção de todos.
Sds,
Mensagens do monitor serial do arduino:
Liga GSM...OK!
Testando GSM Shield SIM900
ATT: OK
RIC:
OK
DB:ELSE
DB:NO RESP
DB:NO RESP
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: 1,50,1,50,1,50
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: 10,"REC UNREAD","27360","","15/09/17,12:38:06-12"
Bradesco: Alanex , com o seu Cartao Bradesco Visa Platinum voce tem cobertura exclusiva com o Seguro de Locacao de Veiculos em qualqu
OK
ATT: OK
RIC:
OK
ATT: ERROR
RIC:
ERROR
DB:STARTING NEW CONNECTION
ATT: SHUT OK
RIC:
SHUT OK
DB:SHUTTED OK
ATT: OK
RIC:
OK
DB:APN OK
ATT: OK
RIC:
OK
DB:CONNECTION OK
ATT: ERROR
RIC:
177.109.177.20
DB:ASSIGNED AN IP
status=Conectado...
ATT: OK
RIC:
OK
DB:RECVD CMD
ATT: CONNECT OK
RIC:
OK
ATT: OK
RIC:
CONNECT OK
DB:OK TCP
ATT: >
RIC:
>
DB:>
ATT: SEND OK
RIC:
SEND FAIL
Failed to send data to the server
0
Código do arduino:/Programa: Arduino GSM Shield SIM900 - Acesso internet
//Autor: Arduino e Cia
//#include "SIM900.h"
#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;
}
}
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("timbrasil.br", "tim", "tim"))
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("temadre.000webhostapp.com", 80, "/add.php", temp_string,msg, 55);
if (numdata)
{
Serial.println("Data sent to server succesfully!");
}
else
{
Serial.println("Failed to send data to the server");
}
delay(5000);
}
Código das páginas PHP:
index.PHP<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
include("connect.php");
$link=Connection();
$result=mysqli_query($link,"SELECT * FROM `SMS_Recebidos` ORDER BY `TimeStamp` DESC");
?>
<html>
<head>
<title>Arduino e Cia - GSM Shield</title>
</head>
<body>
<a href='
http://www.arduinoecia.com.br/' style='display: block'>
<img alt='Arduino e Cia' height='69px; ' id='Header1_headerimg' src='
http://3.bp.blogspot.com/-l1ikBwIytf4/VScJr56C-zI/AAAAAAAADsY/tlWKliR7-lw/s1600/Arduino%2Be%2BCia-Bco.png' style='display: block' width='540px; '/>
</a>
<h1>GSM Shield SIM900 - Registro de SMS</h1>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td align='center' width='160px'><b> Data e Hora </b></td>
<td align='center' width='375px'><b> Mensagem </b></td>
</tr>
<?php
if($result!==FALSE){
while($row = mysqli_fetch_array($result)) {
printf("<tr><td align='center'> %s </td><td> %s </td></tr>",$row["TimeStamp"], $row["SMS_Texto"]);
}
mysqli_free_result($result);
mysqli_close($link);
}
?>
</table>
</body>
</html>
add.php<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
include("connect.php");
$link=Connection();
$MSG_Texto=$_POST["MSG_Texto1"];
$query = "INSERT INTO SMS_Recebidos (`TimeStamp`, `SMS_Texto`)
VALUES (current_timestamp,$MSG_Texto)";
if (mysqli_query($connection,$query)) {
echo "New record created successfully";
} else {
echo "Error:" . $query . "<br>" . mysqli_error($connection);
}
mysqli_close($connection);
header("Location: index.php");
?>
</body>
</html>
connect.php<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
function Connection(){
$server="localhost";
$user="id1250889_alanex";
$pass="pEdroj85";
$db="id1250889_temadre";
$connection = mysqli_connect($server, $user, $pass, $db);
/* check connection */
if (mysqli_connect_errno()) {
die("Connect failed: " . mysqli_connect_error());
}
return $connection;
}
?>
</BODY>
</HTML>