-1

Thanks for taking time to read my post. Ill try just cover what i believe to be important to the problem but i'm not a professional coder so please bear with me.

I have a SIM900 module with an Arduino Mega, and am trying to use the http get function to send data to a mySQL database. I have successfully used the SIM900 to create text files in my .ftp server so i know it works to some degree, just not the http function. I have a .php script which works fine when i use it through my browser (eg. visiting "mysite.epizy.com/senddata.php?sensor69=69" will return in the browser:

Array ( [sensor69] => 69 [__test] => dfc33491ff131abef9348da81e436528 [_ga] => GA1.2.428043981.1572933465 )

When i try connect with the SIM900 i get the following on my serial:

    setting connection type
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK

AT+SAPBR=3,1,"APN","WWW.vodafone.net.nz"

OK

AT+SAPBR=1,1

ERROR

AT+SAPBR=2,1

+SAPBR: 1,1,"121.90.164.49"

OK

AT+HTTPINIT

OK

AT+HTTPPARA="CID",1

OK

AT+HTTPPARA="URL","mysite.epizy.com/send_data.php?sensor69=69"



OK

AT+HTTPACTION=0

OK
⸮⸮

+HTTPACTION:0,200,859
⸮
AT+HTTPREAD

+HTTPREAD:859
<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&ar
AT+HTTPTERM

OK

As we can see on the HTTPREAD function returns 859 characters but this seems to be truncated, and there is no registration in my database or log file (created/updated within the .php) This is my .php script "senddata.php"

<?php

print_r($_REQUEST);

    //log php activation
 

date_default_timezone_set("Pacific/Auckland");

$my_file = 'log.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
$new_data = "\n"."Module=".$_GET['moduleID'].", ". date("d:m:Y")." ". date("h/i/sa");
fwrite($handle, $new_data);
fclose($handle);

// Prepare variables for database connection
    $dbusername = "epiz_69696969";  // enter database username, I used "arduino" in step 2.2
    $dbpassword = "69696969696969";  // enter database password, I used "arduinotest" in step 2.2
    $server = "sql169.epizy.com"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com"


    $moduleID=$_GET['moduleID'];

    // Connect to your database

    $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
    $dbselect = mysql_select_db("epiz_24743320_testData",$dbconnect);

    // Prepare the SQL statement

    $sql = "INSERT INTO simData2 (moduleID) VALUES ('$moduleID')";


    // Execute SQL statement

    mysql_query($sql);
    mysql_close();

?>

Here is the section of my arduino code for the http connect:

void httpConnect() {
 
    myGsm.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""); // Set type of internet connection to GPRS context
    delay(1000);
    Serial.println(" setting connection type");
    printSerialData();
    myGsm.println("AT+SAPBR=3,1,\"APN\",\"WWW.vodafone.net.nz\""); // Set access point name
    delay(1000);
    printSerialData();
    myGsm.println("AT+SAPBR=1,1"); // Enable GPRS connection
    delay(1000);
    printSerialData();
    myGsm.println("AT+SAPBR=2,1");  // To check connection status
    delay(5000);
    printSerialData();
    
    myGsm.println("AT+HTTPINIT");                  // Initialize HTTP
    delay(500);
    printSerialData();
    myGsm.println("AT+HTTPPARA=\"CID\",1");    // End the PARA ???
    delay(500);
    printSerialData();
    
    myGsm.print("AT+HTTPPARA=\"URL\",\"mysite.epizy.com/send_data.php?sen69=69\""); // Send PARA command, set url to send data
        
            
    
    
           delay(2000);
    printSerialData();
       delay(2000);
    printSerialData();
    myGsm.println("");   // close url
    Serial.println("");
    delay(500);
    printSerialData();
    delay(500);
    myGsm.println("AT+HTTPACTION=0"); //HTTP method 0-get 1-post 2-head
    delay(1000);
    printSerialData();
        delay(1000);
    printSerialData();
        delay(2000);
    printSerialData();
            delay(2000);
    printSerialData();
            delay(2000);
    printSerialData();
    myGsm.println("AT+HTTPREAD");
            delay(2000);
    printSerialData();
        delay(2000);
    printSerialData();
            delay(2000);
    printSerialData();
    myGsm.println("AT+HTTPTERM");
    delay(100); 
    printSerialData();     

}

If anyone can help shed light on why the SIM900 module is not working to activate my .php at all any help would be so greatly appreciated.

Cheers

  • It does not only seem truncated, but something completely different than what your PHP code should return - I am not seeing any ` – CBroe Aug 07 '20 at 08:04
  • Actually, those scripts appear to be from some “bot detection” functionality, https://stackoverflow.com/questions/31912000/byethost-server-passing-html-values-checking-your-browser-with-json-string – CBroe Aug 07 '20 at 08:05
  • **Warning:** `mysql_*` extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0. Instead, either the [mysqli](https://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](https://www.php.net/manual/en/book.pdo.php) extension should be used. See also the [MySQL API Overview](https://www.php.net/manual/en/mysqlinfo.api.choosing.php) for further help while choosing a MySQL API. – Dharman Aug 07 '20 at 12:26

1 Answers1

0

I have solved the issue. It turns out the server i was using (epizy.com (infinity free)) requires javascript capabilities which the SIM900 does not have (in my current setup at least). I have created a new server with heroku, using pretty much the same .php file (database is postgreSQL not mySQL so some small tweaks) and am now successfully sending data into the database as i require. I still have not resolved the truncating serial responses but this is not necessary for the functionality i'm after.