Hello everyone,
I have a current project that uses the EnOcean TCM310 receiver gateway, receiving sensor data from different STM3xx wireless sensor modules.
I have successfully implemented reading data from the TCM310 through Arduino UART using the EnOcean Serial Protocol (ESP3).
I wanted to transfer these data to a webserver on the cloud (using Amazon Web Services EC2 instance). The webserver is a Bitnami LAMP server on Ubuntu. I have written code based on similar implementations here in the forums. The connection is established between the Arduino client and the cloud web server, but there is a problem with inserting data on the mySQL server. I know that data is not inserted by viewing the database in the phpmyadmin. I had almost a week trying to figure out what's the problem to no avail: tried changing the location of the PHP file (not in the cloud server but on an Xerver local server, specifying the database host with the IP address of the cloud server in the PHP file); tried changing the database host name to localhost:3306, localhost, 127.0.0.1, and the IP address of the cloud server, with the PHP file located on the same machine with the mySQL database; tried changing the way the directory of the PHP file is written in the Arduino code (specifying the file location directly after the DocumentRoot).
Just a note, I'm using PuTty to access SSH for the cloud server instance since my local machine is Windows. Also, whenever I access phpmyadmin, I use tunneling to access via 127.0.0.1:8888, since Bitnami cloud server instances can't be accessed directly on the browser.
Kindly help if there are problems with my code.... or do you think this is a problem with the server configuration? Or is there an issue with using the GET function using the cloud? Somewhat confused on my next steps right now... Thanks!
Arduino Code:
#include <Ethernet.h> //library for ethernet functions
#include <SPI.h> //library for SPI communication (Arduino to Ethernet Shield)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0x41 };
byte ip[] = { 192, 168, 1, 3 };
byte gw[] = { 192, 168, 1, 1 };
//byte server[] = { 182, 18, 208, 3 };
//byte server[] = { 127, 0, 0, 1 };
byte server[] = { 54, 245, 100, 105 }; // Server IP
byte subnet[] = { 255, 255, 255, 0 };
int ledPin=13;
int packet[24]; //used as a rotational buffer
int j=0;
int data=0;
void setup()
{
Serial.begin(57600);
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,HIGH);
delay(500);
digitalWrite(ledPin,LOW);
Serial.println("EnOcean TCM310 reader");
//send_packet(0xAB,0x48,0,0,0,0,0,0,0,0);
}
void loop()
{
    Serial.println("Program running...");
starttime = millis();
    while ( (Serial.available()<25) && ((millis() - starttime) < MAX_MILLIS_TO_WAIT) )
      {}  Â
    if(Serial.available() < 25) //the data didn't come in - handle that problem here
      {
      Serial.println("ERROR - Didn't get 24 bytes of data!");
      }
    else
      {
      for (int j=0; j<24; j++)
        {
        packet[j] = Serial.read(); // Get data.
        if (packet[0] == 0x55)
          {
          switch (j)
            {
            case 0: Serial.print("SYNC:"); break;
            case 1: Serial.print(", Length:"); break;
            case 3: Serial.print(", OpLength:"); break;
            case 4: Serial.print(", Type:"); break;
            case 5: Serial.print(", CRC8H:"); break;
            case 6: Serial.print(", RORG:"); break;
            case 7: Serial.print(", Data:"); break;
            case 10: Serial.print(", LRNbit:"); break;
            case 11: Serial.print(", Sender ID:"); break;
            case 15: Serial.print(", Status:"); break;
            case 16: Serial.print(", SubTel#:"); break;
            case 17: Serial.print(", Dest ID:"); break;
            case 21: Serial.print(", dBm:"); break;
            case 22: Serial.print(", Security:"); break;
            case 23: Serial.print(", CRC8D:"); break;
            }
          Serial.print(packet[j],HEX); Serial.print(" ");
          }
        else
        Serial.println("Eror: Not a valid sensor telegram");
        }
      }
    digitalWrite(ledPin,HIGH); //LED ON to indicate that a packet is read
delay(500);
    digitalWrite(ledPin,LOW ); //LED OFF
    senddata();
}
void senddata()
{
data = packet[9];
EthernetClient client;
Ethernet.begin(mac, ip, subnet);
Serial.println();
Serial.println("Connecting to Web Server...");
delay(1000); //Keeps the connection from freezing
if (client.connect(server, 80))
{
Serial.println("Connected!");
client.print("GET /avislinktest.php?t0=");
            Serial.print("GET /avislinktest.php?t0=");
            client.print(data);
            Serial.print(data);
            client.println(" HTTP/1.1");
            Serial.println(" HTTP/1.1");
            client.println("Host: 54.245.100.105");
            Serial.println("Host: 54.245.100.105");
            client.println("User-Agent: Arduino");
            Serial.println("User-Agent: Arduino");
            client.println("Accept: text/html");
            Serial.println("Accept: text/html");
            client.println();
Serial.println();
            //readPage();
delay (9800);
}
else
{
Serial.println("Connection unsuccesfull");
}
 //}
//stop client
client.stop();
while(client.status() != 0)
delay(5);
}
PHP file:
<?php
$value = $_GET['t0'];
echo date("d.m.Y-H:i:s") . " Temperature 1 = " . "$value";
$link = mysql_connect("localhost:3306", "username", "password") or die("Error: Cannot connect to Database" . mysql_error());
mysql_select_db("avislink") or die("Error: Cannot connect to Data Table" . mysql_error());
$query = "INSERT INTO temp (dataID, sensorID, time, sensorvalue) VALUES (1, 'AL-01-0001-UT', NOW(), '$value' )";
$result = mysql_query($query) or die("Unsuccessful writing to Database " . mysql_error());
mysql_close($link);
?>