Discussione WeMos inviare dati database

CaffeLatte

Utente Electrum
17 Gennaio 2013
263
53
26
170
Buongiorno,
Vorrei inviare alcuni valori rilevati con WeMos ad un server locale(xampp), pensavo di collegarmi tramite wemos ad una pagina passando in GET i valori ma non funziona,

-script PHP della pagina:
PHP:
<?php
require_once '../model/dbconnect.php'; //conessione database
if (isset($_GET["c"])) {
    # code...
    $codice = $_GET["c"]; //parametro di prova che ricevo
   
    $stmts = $conn->prepare("INSERT INTO prova(codice) VALUES(?)"); //inserisco valori
    $stmts->bind_param("s", $codice);
    $res = $stmts->execute();
    $stmts->close();
?>

-codice arduino:
Codice:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

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

void setup () {

  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    delay(1000);
    Serial.print("Connecting..");

  }

}

void loop() {

  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

    HTTPClient http;  //Declare an object of class HTTPClient
  String mac = WiFi.macAddress();
   Serial.println(http.begin("localhost/Sito-Web-Tesina/pages/arduino.php?c="+mac ));  //Specify request destination
    int httpCode = http.GET();                                                                  //Send the request
    Serial.println(mac);
   
   
    if (httpCode > 0) { //Check the returning code

      String payload = http.getString();   //Get the request response payload
      Serial.println(payload);                     //Print the response payload

    }

    http.end();   //Close connection

  }

  delay(30000);    //Send a request every 30 seconds

}
Ringrazio per l'aiuto
 
Probabile che l'errore sia nel codice PHP. Non hai chiuso il blocco if (non hai scritto la parentesi graffa } per intenderci).

Se l'errore non è questo allora devi fare un po' di debug e scovare il bug appunto.

Ah, e poi prova a passare i parametri GET tramite browser, se funziona allora vuol dire che l'errore è nel codice arduino.
 
Dovresti mettere l'IP della macchina dove si trova il server quando fai la richiesta dall'Arduino. Se non ho capito male il server non sta lì quindi puntando su localhost non lo trova.
 
  • Mi piace
Reazioni: driverfury