So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By davidli3100
#72461 Hi guys,
I'm pretty new to this whole IoT thing or just using wifi with arduino in general.

How would I go about sending values computed on the arduino to a web server so I can further manipulate the data?

Are there any free alternatives for this? I know data.sparkfun.com was one but it seems to be unavailable. Or, how would I do this myself using my own website?

Thanks in advance
David
User avatar
By villTech
#72614 1. create text file on your document root. create php file (ie. write.php) writing data to your text file. add php or ajax to your web app to display text file content. on your esp8266, send http POST request to your write.php file.

2. setup database (ie. MySQL) to your web host. create php file writing values to your database. add php on your web app to read/display database content. on your esp8266, send http POST request to your php file.

3. set up mqtt broker to your web host. on your esp8266, publish data to a topic. on your web app, add js code to connect to mqtt broker, subscribe to a topic esp8266 is sending data, and display data received. you can also use 3rd party mqtt broker.

4. there are other ways.
User avatar
By hortplus
#72696 I use this to send to my mysql database:

#include <ESP8266WiFi.h>

const char* ssid = "....";
const char* password = "...";

const char* host = "www.hort.com";


void setup()
{
Serial.begin(115200);
Serial.println();

Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
}


void loop()
{
WiFiClient client;

Serial.printf("\n[Connecting to %s ... ", host);
if (client.connect(host, 80))
{
Serial.println("connected]");

client.print("GET /write.php?"); // This
client.print("logger=123&loggerstart=10&loggerend=10&temperature=10&leafwetness=10"); // This
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: www.hort.com"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server
Serial.println("[Response:]");
while (client.connected())
{
if (client.available())
{
String line = client.readStringUntil('\n');
Serial.println(line);
}
}
client.stop();
Serial.println("\n[Disconnected]");
}
else
{
Serial.println("connection failed!]");
client.stop();
}
delay(10000);
}