Advertisement
mayerm001

Bell

Mar 23rd, 2023 (edited)
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | Source Code | 0 0
  1. // Door Bell
  2. // Copyright (c) Mayer Mihály 2020-Jul
  3. // version 2.0
  4. #include <ESP8266WiFiMulti.h>
  5. #include <ESP8266HTTPClient.h>
  6. #include <Wire.h>
  7.  
  8. const char* serverURL = "http://192.168.0.23:8585/post-bell-signal.php";
  9. const String apiKeyValue = "...";
  10.  
  11. boolean connectToWifi()
  12. {
  13.   char WiFiPassword[] = "...";    
  14.   ESP8266WiFiMulti wifiMulti;
  15.   IPAddress ip(192, 168, 0, 92); //  change
  16.   IPAddress gateway(192, 168, 0, 1);
  17.   IPAddress subnet(255, 255, 255, 0);
  18.  
  19.   wifiMulti.addAP("TP-LINK-2", WiFiPassword);
  20.   wifiMulti.addAP("thome2", WiFiPassword);
  21.   wifiMulti.addAP("TP-LINK", WiFiPassword);
  22.   wifiMulti.addAP("ricsi", WiFiPassword);
  23.   while (wifiMulti.run() != WL_CONNECTED)
  24.     delay(500);
  25.   WiFi.config(ip, gateway, subnet);
  26. }
  27.  
  28. void setup() {
  29.   connectToWifi();
  30.   sendValues_to_database(serverURL, apiKeyValue,"0", "The doorbell rang");
  31.   ESP.deepSleep(0);  
  32. }
  33.  
  34. void sendValues_to_database(String server, String key,String ntype, String message)
  35. {
  36.   HTTPClient http;
  37.   http.begin(server);
  38.   http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  39.   String httpRequestData = "api_key=" + key
  40.                            + "&ntype=" + ntype
  41.                            + "&message=" + message;
  42.   int httpResponseCode = http.POST(httpRequestData);
  43.   http.end();
  44. }
  45.  
  46. void loop() {
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement