I need to know how can i send my raw data (1 or 0) to php script to process the data and send to mysql database. I'm using wired arduino ethernet shield. I have try many solution i can get from the internet, but none succeed. I need help to understand how to send the data and improve my code.
Thank you for helping.
Here are my sketch to get the data.
/********************************
* Libraries included
*******************************/
#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>
/********************************
* Constants and objects
*******************************/
/* Assigns the Ubidots parameters */
char const * TOKEN = "A1E-KIoScrrIu1RTgxDSlKYy1WA3NWQ9Kq"; // Assign your Ubidots TOKEN
char const * VARIABLE_LABEL_1 = "sensor"; // Assign the unique variable label to send the data
/* Enter a MAC address for your controller below */
/* Newer Ethernet shields have a MAC address printed on a sticker on the shield */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
/* initialize the instance */
Ubidots client(TOKEN);
/********************************
* Main Functions
*******************************/
int floatswitch = 7;
void setup() {
Serial.begin(9600);
pinMode(floatswitch, INPUT);
//client.setDebug(true);// uncomment this line to visualize the debug message
/* start the Ethernet connection */
Serial.print(F("Starting ethernet..."));
if (!Ethernet.begin(mac)) {
Serial.println(F("failed"));
} else {
Serial.println(Ethernet.localIP());
}
/* Give the Ethernet shield a second to initialize */
delay(2000);
Serial.println(F("Ready"));
}
void loop() {
Ethernet.maintain();
/* Sensors readings */
int result = digitalRead(floatswitch);
/* Sending values to Ubidots */
client.add(VARIABLE_LABEL_1, result);
client.sendAll();
delay(5000);
}