This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
maakplek_statusmelder [2019/03/13 13:54] – created wrusman | maakplek_statusmelder [2019/03/13 15:18] – wrusman | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Maakplek statusmelder ====== | ||
+ | |||
+ | ==== Schakelaar box met ESP8266 ==== | ||
+ | |||
+ | De ESP8266 maakt verbinding met wifi en stuurt bij het omhalen van de schakelaar een bericht naar de twitter API van pushingbox. Zijn 3.3v voeding krijgt hij via een spanningsregelaar die is aangesloten op de vcc uitgang van de pro micro.\\ | ||
+ | |||
+ | code voor de esp8266: | ||
+ | < | ||
+ | #include < | ||
+ | |||
+ | #define AP_SSID | ||
+ | #define AP_PASSWORD " | ||
+ | |||
+ | #define API_SERVER | ||
+ | #define API_KEY | ||
+ | |||
+ | #define ledPin 0 | ||
+ | #define switchPin 2 | ||
+ | |||
+ | int switchState = false; | ||
+ | int lastSwitchState = false; | ||
+ | int lastConnected = false; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | pinMode(switchPin, | ||
+ | pinMode(ledPin, | ||
+ | wifiConnect(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | switchState = digitalRead(switchPin); | ||
+ | if (switchState != lastSwitchState) { | ||
+ | if (switchState == HIGH) { | ||
+ | WiFiClient client; | ||
+ | if (!client.connect(API_SERVER, | ||
+ | { | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | client.print(" | ||
+ | client.print(API_KEY); | ||
+ | client.print("& | ||
+ | client.println(" | ||
+ | client.print(" | ||
+ | client.println(API_SERVER); | ||
+ | client.println(); | ||
+ | |||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | delay(10); | ||
+ | } | ||
+ | else { | ||
+ | WiFiClient client; | ||
+ | if (!client.connect(API_SERVER, | ||
+ | { | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | client.print(" | ||
+ | client.print(API_KEY); | ||
+ | client.print("& | ||
+ | client.println(" | ||
+ | client.print(" | ||
+ | client.println(API_SERVER); | ||
+ | client.println(); | ||
+ | |||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | delay(10); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | lastSwitchState = switchState; | ||
+ | |||
+ | } | ||
+ | void wifiConnect() | ||
+ | { | ||
+ | Serial.print( " | ||
+ | Serial.print( AP_SSID ); | ||
+ | WiFi.begin( AP_SSID, AP_PASSWORD ); | ||
+ | while ( WiFi.status() != WL_CONNECTED ) | ||
+ | { | ||
+ | delay( 1000 ); | ||
+ | Serial.print( " | ||
+ | } | ||
+ | |||
+ | Serial.println( "" | ||
+ | Serial.println( "WiFi connected" | ||
+ | |||
+ | Serial.println( WiFi.localIP( ) ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Telefoonbox met Arduino pro micro ==== | ||
+ | De arduino pro micro is via USB-OTG verbonden met een lader en de telefoon zodat de telefoon oplaad en via muis/ | ||
+ | Via deze methode wordt via keyboard commando' | ||
+ | |||
+ | {{:: | ||
+ | |||
+ | |||
+ | Code voor de Arduino Pro Mini: | ||
< | < | ||
#include " | #include " |