Skip to content

Instantly share code, notes, and snippets.

@HermanKopinga
Last active May 1, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HermanKopinga/c2e19173c9ea10b44fb4f15e708eff70 to your computer and use it in GitHub Desktop.
Save HermanKopinga/c2e19173c9ea10b44fb4f15e708eff70 to your computer and use it in GitHub Desktop.
Raamsensor code @ Maakplek
/**
* Based on BasicHTTPClient.ino
* modifications by herman@kopinga.nl
*
* connects to ESPEasy at 192.168.1.142
*
* Created in: 2017
*
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
void setup() {
pinMode(2, INPUT_PULLUP);
USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFiMulti.addAP("wifissid", "wifipass");
}
void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
if (digitalRead(2)) {
// http.begin("http://192.168.1.142/control?cmd=oled,3,1,Textiel%20%20%20%20%20OPEN"); //HTTP
// http.begin("http://192.168.1.142/control?cmd=oled,4,1,Assemblage%20%20OPEN"); //HTTP
http.begin("http://192.168.1.142/control?cmd=oled,5,1,Houtplek%20%20%20%20OPEN"); //HTTP
Serial.print("open");
} else {
// http.begin("http://192.168.1.142/control?cmd=oled,3,1,Textiel%20%20%20%20dicht"); //HTTP
// http.begin("http://192.168.1.142/control?cmd=oled,4,1,Assemblage%20dicht"); //HTTP
http.begin("http://192.168.1.142/control?cmd=oled,5,1,Houtplek%20%20%20dicht"); //HTTP
Serial.print("dicht");
}
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
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
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
delay(5000);
}
#!/bin/bash
# Meta-Monitoring part of the loosly coupled windowmonitor @ Maakplek.nl
# Blame herman@kopinga.nl...
# Yeah, bash does functions and variables, I'm just happy it works :)
ping -c 1 -w3 ESP_999743 1> /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
echo "Textiel gevonden"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,6,1,%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20 -q -O/dev/null
else
echo "Textiel moet herstart"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,6,1,Textiel%20stuk -q -O/dev/null
fi
ping -c 1 -w3 ESP_1028DB 1> /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
echo "Hout gevonden"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,7,1,%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20 -q -O/dev/null
else
echo "Hout moet herstart"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,7,1,Hout%20stuk -q -O/dev/null
fi
ping -c 1 -w3 ESP_103204 1> /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
echo "Assemblage gevonden"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,8,1,%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20 -q -O/dev/null
else
echo "Assemblage moet herstart"
/usr/bin/wget http://192.168.1.142/control?cmd=oled,8,1,Assemblage%20stuk -q -O/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment