0

I have ESP8266 NodeMcu and want to send and update MySql database with data like temperature and humidty using websocket not Httprequest.

I am using this sample of code in ESP8266 as client:

   #include <WiFi.h>
    #include <WebSocketClient.h>

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

    char path[] = "/echo";
    char host[] = "mysite.com";

    WebSocketClient webSocketClient;
    WiFiClient client;

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

      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());

      delay(5000);

      if (client.connect(host, 80)) {
        Serial.println("Connected");
      } else {
        Serial.println("Connection failed.");
      }

      webSocketClient.path = path;
    webSocketClient.host = host;
      if (webSocketClient.handshake(client)) {
        Serial.println("Handshake successful");
      } else {
        Serial.println("Handshake failed.");
      }

    }

    void loop() {
      String data;

      if (client.connected()) {

        webSocketClient.sendData("Info to be echoed back");

        webSocketClient.getData(data);
        if (data.length() > 0) {
          Serial.print("Received data: ");
          Serial.println(data);
        }

      } else {
        Serial.println("Client disconnected.");
      }

      delay(3000);

    }

I want to know how to do it in my website host. for example I want to know what do in my php files to receive the data from ESP8266 and update my MySql table.

Mohammad Khaled
  • 19
  • 2
  • 13
  • You did not write about code you have tried so far. If you did not try PHP code yet, maybe check their documentation on setting up websocket server? – ahwayakchih Oct 06 '19 at 08:20
  • Maybe this will help you a bit: https://stackoverflow.com/a/14515205/6352710 – ahwayakchih Oct 06 '19 at 08:32

0 Answers0