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

User avatar
By hortplus
#73306 i'm trying to send data to a mysql database. I have written the php script to store data. Works well. However sending from my wemos r1 d1 doesn't seem to work. I have put:



void loop() {
printWifiStatus();
// Connect to the server (your computer or web page)
if (client.connect(server, 80)) {
Serial.println("--> connection ok\n");
Serial.println("1000");
client.print("GET /write_met.php?"); // This is the get request
client.print("temperature="); // This is the temperature
client.print("100"); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
client.print("&leafwetness=");
client.print("100");
client.println(" HTTP/1.1"); // Part of the GET request
client.print( "Host: " );
client.println(server);
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("--> finished transmission\n");

Anything obvious with what i'm doing wrong?
User avatar
By hortplus
#73350 I ended up with this:

#include <ESP8266WiFi.h>

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

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

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
delay(5000);
++value;

Serial.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

// We now create a URI for the request
String url = "/write_met.php?logger=200&temperature=10&leafwetness=10";

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(60000);

// Read all the lines of the reply from server and print them to Serial
Serial.println("Respond:");
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}

Serial.println();
Serial.println("closing connection");
}


Others might find it useful