Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

65 righe
1.6 KiB

  1. #ifdef ESP32
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4. #else
  5. #include <ESP8266WiFi.h>
  6. #include <ESP8266HTTPClient.h>
  7. #include <WiFiClient.h>
  8. #endif
  9. #include <Wire.h>
  10. const char* ssid = "Wifiname";
  11. const char* password = "password";
  12. const char* serverName = "https://scholarspedia.com/Neonflake/post-esp-data.php";
  13. String apiKeyValue = "Neonflake0799";
  14. void setup() {
  15. Serial.begin(9600);
  16. WiFi.begin(ssid, password);
  17. Serial.println("Connecting");
  18. while(WiFi.status() != WL_CONNECTED) {
  19. delay(500);
  20. Serial.print(".");
  21. }
  22. Serial.println("");
  23. Serial.print("Connected to WiFi network with IP Address: ");
  24. Serial.println(WiFi.localIP());
  25. }
  26. void loop() {
  27. //Add your code here
  28. //End your code here
  29. if(WiFi.status()== WL_CONNECTED){
  30. HTTPClient http;
  31. http.begin(serverName);
  32. http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  33. //Change your names here
  34. String httpRequestData = "api_key=" + apiKeyValue + "&temperature=" + Temp_value + "&luminosity=" + Lumi_value + "&pH=" + pH_value + "";
  35. //Dont edit anything below
  36. int httpResponseCode = http.POST(httpRequestData);
  37. if (httpResponseCode>0) {
  38. if(httpResponseCode==200){
  39. Serial.print("Server succesfully updated");
  40. Serial.println("");
  41. }
  42. else{
  43. Serial.print("HTTP Response code: ");
  44. Serial.print(httpResponseCode);
  45. Serial.println("");
  46. }
  47. }
  48. else {
  49. Serial.print("Error code: ");
  50. Serial.println(httpResponseCode);
  51. }
  52. http.end();
  53. }
  54. else {
  55. Serial.println("WiFi Disconnected");
  56. }
  57. delay(900000);
  58. }