Last active
June 12, 2016 20:12
-
-
Save tiefpunkt/dde2d222873e1d990430935d2c3d2952 to your computer and use it in GitHub Desktop.
Arduino Betriebsstundenzähler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IN_PIN 13 | |
#define ON HIGH | |
#define OFF LOW | |
#define IGNORE_THRESHOLD 500 | |
long starttime, duration; | |
int curr_status, prev_status; | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WiFiMulti.h> | |
#include <ESP8266HTTPClient.h> | |
ESP8266WiFiMulti WiFiMulti; | |
void setup() { | |
WiFiMulti.addAP("munichmakerlab", "*********"); | |
Serial.begin(9600); | |
pinMode(IN_PIN, INPUT); | |
starttime = 0; | |
prev_status = OFF; | |
} | |
void loop() { | |
WiFiMulti.run(); | |
curr_status = digitalRead(IN_PIN); | |
if (curr_status != prev_status) { | |
if (curr_status == ON) { | |
Serial.println("Start"); | |
starttime = millis(); | |
} else { | |
duration = millis() - starttime; | |
if (duration > IGNORE_THRESHOLD) { | |
Serial.println("Stop"); | |
Serial.print("Duration [ms]: "); | |
Serial.println(duration); | |
Serial.print("Duration [s]: "); | |
Serial.println(duration/1000); | |
Serial.println(); | |
HTTPClient http; | |
String t = String(duration/1000); | |
http.begin("http://10.10.20.64/cgi-bin/data_laser.pl?duration=" + t); | |
int httpCode = http.GET(); | |
// httpCode will be negative on error | |
if(httpCode > 0) { | |
// HTTP header has been send and Server response header has been handled | |
Serial.printf("[HTTP] GET... code: %d\n", httpCode); | |
// file found at server | |
if(httpCode == HTTP_CODE_OK) { | |
String payload = http.getString(); | |
Serial.println(payload); | |
} | |
} else { | |
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); | |
} | |
http.end(); | |
Serial.println(); | |
} | |
} | |
} | |
prev_status = curr_status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment