Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Door Bell
- // Copyright (c) Mayer Mihály 2020-Jul
- // version 2.0
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266HTTPClient.h>
- #include <Wire.h>
- const char* serverURL = "http://192.168.0.23:8585/post-bell-signal.php";
- const String apiKeyValue = "...";
- boolean connectToWifi()
- {
- char WiFiPassword[] = "...";
- ESP8266WiFiMulti wifiMulti;
- IPAddress ip(192, 168, 0, 92); // change
- IPAddress gateway(192, 168, 0, 1);
- IPAddress subnet(255, 255, 255, 0);
- wifiMulti.addAP("TP-LINK-2", WiFiPassword);
- wifiMulti.addAP("thome2", WiFiPassword);
- wifiMulti.addAP("TP-LINK", WiFiPassword);
- wifiMulti.addAP("ricsi", WiFiPassword);
- while (wifiMulti.run() != WL_CONNECTED)
- delay(500);
- WiFi.config(ip, gateway, subnet);
- }
- void setup() {
- connectToWifi();
- sendValues_to_database(serverURL, apiKeyValue,"0", "The doorbell rang");
- ESP.deepSleep(0);
- }
- void sendValues_to_database(String server, String key,String ntype, String message)
- {
- HTTPClient http;
- http.begin(server);
- http.addHeader("Content-Type", "application/x-www-form-urlencoded");
- String httpRequestData = "api_key=" + key
- + "&ntype=" + ntype
- + "&message=" + message;
- int httpResponseCode = http.POST(httpRequestData);
- http.end();
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement