0

I'm working on a project to send data to my website, With an Arduino and a SIM900, I just made an AT code to send the data to the website and use PHP with it, but my PHP file doesn`t seem to receive the value sent from the SIM900 AT commands, why? Another question that I have, is the AT command safe to send data to the website? Thanks for the help and have a great day. This is code I currently have:

This is what I have right now for the sim900:

void setup(){
  //Inicialize Serial and SIM
  Serial.begin(19200);
  SIM900.begin(19200);

  delay(7000);

  // See if the SIM900 is ready
  SIM900.println("AT");
  ReceberEFim();                                 
  delay(4000);

  // SIM card inserted and unlocked?
  SIM900.println("AT+CPIN?");
  ReceberEFim();
  delay(500);              

  // Is the SIM card registered?
  SIM900.println("AT+CREG?");
  ReceberEFim();                            
  delay(500);

  // Is GPRS attached?
  SIM900.println("AT+CGATT?");
  ReceberEFim();                           
  delay(500);

  // Check signal strength - should be 9 or higher
  SIM900.println("AT+CSQ");
  ReceberEFim();                              
  delay(500);

  // Set connection type to GPRS
  SIM900.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  ReceberEFim();      
  delay(1000);

  // Set the APN - this will depend on your network/service provider
  SIM900.println("AT+SAPBR=3,1,\"APN\",\"claro.com.br\"");
  ReceberEFim();      
  delay(1000);

  // Enable GPRS - this will take a moment or two
  SIM900.println("AT+SAPBR=1,1");
  ReceberEFim();                      
  delay(3000);

  // Check to see if connection is correct and get your IP address
  SIM900.println("AT+SAPBR=2,1");
  ReceberEFim();                        
  delay(500);

  // Enable HTTP mode
  SIM900.println("AT+HTTPINIT");
  ReceberEFim();                        
  delay(2000);

  SIM900.println("AT+HTTPPARA=\"URL\",\"http://mywebsite.com/teste.php?s1=50\"");
  ReceberEFim();
  delay(2000);                               

  SIM900.println("AT+HTTPPARA=\"CID\",1");
  ReceberEFim();             
  delay(500);

  SIM900.println("AT+HTTPACTION=0");
  ReceberEFim();                   
  delay(500);

  // Close the HTTP connection
  SIM900.println("AT+HTTPTERM");
  ReceberEFim();

  // Disconnect the GPRS
  SIM900.println("AT+SAPBR=0,1");
  ReceberEFim();
}

This is the PHP file:

   <?php 
    $sensor1 = $_GET["s1"];
    $sensor2 = $_GET["s2"];
    $sensor3 = $_GET["s3"];

    echo "Sensor 1 = $sensor1";
    echo "</br>Sensor 2 = $sensor2";
    echo "</br>Sensor 3 = $sensor3";

  ?>

I expect to be able to send multiple data via SIM900 to my PHP file.

Nilton Sf
  • 19
  • 5
  • 1
    You should [never, never, never ever use delay like that](https://stackoverflow.com/a/46064206/23118). You need to **read and parse** the responses the modem sends back. – hlovdal Sep 30 '19 at 21:56

1 Answers1

0

You don't have passed s2 and s3 in your url, so you can't acess to it and it will produce an error.

You can detect s{n} var dynamically or try isset to check if var exist.

I think it will be better to use https for security reason and sessions or a token to be sure it isn't someone else who try to send random values to you site.

I wish it will help you,

  • Hey, I tried to pass the other 2 parameters (s2 and s3) but I get this weird error, in which it does allow my URL to finish printing, I have added a delay but it does make any difference. This is what I implemented: SIM900.print("AT+HTTPPARA=\"URL\",\"mywebsite.com.br/teste.php?s1=72&s2=32&s3=8\""); and this is the error that I get AT+HTTPPARA="URL","http://mywebsite.com.br/teste.php?s1=72&s2=32AT+HTTPPARA="CID",1 – Nilton Sf Sep 30 '19 at 19:44