Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- POHL Dash Button NG V1
- 17.02.2018
- by Kay Pohl
- */
- /*
- ##############################################################################################
- ##############################################################################################
- _____ _ _
- |_ _| | | | |
- | | _ __ ___| |_ _ __| | ___
- | | | '_ \ / __| | | | |/ _` |/ _ \
- _| |_| | | | (__| | |_| | (_| | __/
- |_____|_| |_|\___|_|\__,_|\__,_|\___|
- ##############################################################################################
- ##############################################################################################
- */
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266HTTPUpdateServer.h>
- /*
- ##############################################################################################
- ##############################################################################################
- _____ __ _
- | __ \ / _(_)
- | | | | ___| |_ _ _ __ ___
- | | | |/ _ \ _| | '_ \ / _ \
- | |__| | __/ | | | | | | __/
- |_____/ \___|_| |_|_| |_|\___|
- ##############################################################################################
- ##############################################################################################
- */
- #define LED 2 // GPIO2 - Led
- #define SETUP_BUTTON 12 // Webupdate Button
- /*
- ##############################################################################################
- ##############################################################################################
- _ _ _
- | | | | | |
- | |__| | __ _ _ __ __| |_ ____ _ _ __ ___
- | __ |/ _` | '__/ _` \ \ /\ / / _` | '__/ _ \
- | | | | (_| | | | (_| |\ V V / (_| | | | __/
- |_| |_|\__,_|_| \__,_| \_/\_/ \__,_|_| \___|
- ##############################################################################################
- ##############################################################################################
- */
- ADC_MODE(ADC_VCC); //vcc read
- /*
- ##############################################################################################
- ##############################################################################################
- _____ _
- | __ \ | |
- | |__) |_ _ _ __ __ _ _ __ ___ ___| |_ ___ _ __
- | ___/ _` | '__/ _` | '_ ` _ \ / _ \ __/ _ \ '__|
- | | | (_| | | | (_| | | | | | | __/ || __/ |
- |_| \__,_|_| \__,_|_| |_| |_|\___|\__\___|_|
- ##############################################################################################
- ##############################################################################################
- */
- //Wifi
- const char* host = "dash-webupdate";
- const char* ssid = "xxx";
- const char* password = "xxx";
- //Server
- const String server_ip = "xxx0";
- const String server_port = "3777";
- const String server_webhook = "/hook/dash_buero/";
- const String server_add = "?VCC=";
- //Hardware
- boolean mSetupButton = LOW;
- int ledState = HIGH;
- unsigned long previousMillis = 0;
- const long interval = 500;
- /*
- ##############################################################################################
- ##############################################################################################
- _____ _
- / ____| | |
- | (___ ___| |_ _ _ _ __
- \___ \ / _ \ __| | | | '_ \
- ____) | __/ |_| |_| | |_) |
- |_____/ \___|\__|\__,_| .__/
- | |
- |_|
- ##############################################################################################
- ##############################################################################################
- */
- ESP8266WebServer httpServer(80);
- ESP8266HTTPUpdateServer httpUpdater;
- void setup() {
- // Setup Webupdate Button
- pinMode(SETUP_BUTTON, INPUT_PULLUP);
- // LED Output
- pinMode(LED, OUTPUT); // Port als Ausgang schalten
- // Connect with WIFI
- Serial.begin(115200);
- WiFi.hostname("dash_buero");
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting..");
- }
- Serial.println("Connected ...");
- // Setup httpUpdater
- MDNS.begin(host);
- httpUpdater.setup(&httpServer);
- httpServer.begin();
- MDNS.addService("http", "tcp", 80);
- //Read Setup Button
- if (digitalRead(SETUP_BUTTON) == HIGH) {
- webhook();
- }
- Serial.println("Webupdate started ...");
- }
- /*
- ##############################################################################################
- ##############################################################################################
- _
- | |
- | | ___ ___ _ __
- | | / _ \ / _ \| '_ \
- | |___| (_) | (_) | |_) |
- |______\___/ \___/| .__/
- | |
- |_|
- ##############################################################################################
- ##############################################################################################
- */
- void loop() {
- //HTTPServer Handle Client
- httpServer.handleClient();
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- // save the last time you blinked the LED
- previousMillis = currentMillis;
- // if the LED is off turn it on and vice-versa:
- if (ledState == LOW) {
- ledState = HIGH;
- }
- else {
- ledState = LOW;
- }
- // set the LED with the ledState of the variable:
- digitalWrite(LED, ledState);
- }
- }
- /*
- ##############################################################################################
- ##############################################################################################
- __ __ _ _ _
- \ \ / / | | | | | |
- \ \ /\ / /__| |__ | |__ ___ ___ | | __
- \ \/ \/ / _ \ '_ \| '_ \ / _ \ / _ \| |/ /
- \ /\ / __/ |_) | | | | (_) | (_) | <
- \ / \/ \___|_.__/|_| |_|\___/ \___/|_|\_\
- ##############################################################################################
- ##############################################################################################
- */
- void webhook() {
- // Onboard LED ON
- digitalWrite(LED, LOW);
- // Read internal VCC
- float vdd = ESP.getVcc() / 1000.0;
- vdd = vdd + 0.1;
- String vdd_string;
- vdd_string = String(vdd);
- // If Wifi is connected send Webhook and then goto deepsleep
- // Check WiFi connection status
- if (WiFi.status() == WL_CONNECTED) {
- // Declare an object of class HTTPClient
- HTTPClient http;
- delay(100);
- // Set address
- http.begin("http://"+server_ip+":"+server_port+server_webhook+server_add+vdd_string);
- //Send the request
- int httpCode = http.GET();
- //Close connection
- http.end();
- //Print address
- Serial.println("http://" + server_ip + ":" + server_port + server_webhook + server_add + vdd_string);
- }
- // Onboard LED OFF
- digitalWrite(LED, HIGH);
- // Go into DeepSleep
- Serial.print("Good Night ...");
- ESP.deepSleep(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement