Merge pull request 'fiveopschanges' (#1) from fiveop/doorstatus:fiveopschanges into master
Reviewed-on: http://git.nr18.space:3000/berhsi/doorstatus/pulls/1
This commit is contained in:
commit
64937e7ea9
12 changed files with 124 additions and 0 deletions
26
README.md
Normal file
26
README.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# KrautStatus
|
||||||
|
|
||||||
|
This repository contains documentation and sources of KrautStatus. KrautStatus
|
||||||
|
is the n-th iteration of a software/hardware project to communicate whether
|
||||||
|
Jena's Krautspace is open or closed.
|
||||||
|
|
||||||
|
KrautStatus consists of three components: an Arduino-sensor-combination at the
|
||||||
|
door, a Python script on a local server, and an API file served on by web
|
||||||
|
server.
|
||||||
|
|
||||||
|
The Arduino broadcasts the current state of the door lock to our LAN. The state
|
||||||
|
is determined by a reed sensor in the door lock. In addition, it controls an
|
||||||
|
RGB LED matrix shield that provides a visual indication of the door locks's
|
||||||
|
state in the room.
|
||||||
|
|
||||||
|
The python script polls the broadcast state and pushes changes to Twitter,
|
||||||
|
Mastodon and our API file.
|
||||||
|
|
||||||
|
The API file is just that, a JSON file. It contains, among other things, the
|
||||||
|
current state of the door lock.
|
||||||
|
|
||||||
|
## Arduino
|
||||||
|
|
||||||
|
## Python Script
|
||||||
|
|
||||||
|
## API
|
11
source/arduino/config.h
Normal file
11
source/arduino/config.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// SSID and password of the WiFi network to which we broadcast the door lock's
|
||||||
|
// status.
|
||||||
|
char SSID[] = "";
|
||||||
|
char PASSWORD[] = "";
|
||||||
|
|
||||||
|
|
||||||
|
// Port on which to listen for status requests
|
||||||
|
unsigned int PORT = 12345;
|
||||||
|
|
||||||
|
// Pin to which the reed switch is connected
|
||||||
|
uint8_t REED_PIN = 0;
|
87
source/arduino/door_status.ino
Normal file
87
source/arduino/door_status.ino
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <WiFi101.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
uint8_t OPEN = 1;
|
||||||
|
uint8_t CLOSED = 0;
|
||||||
|
|
||||||
|
int wifi_status = WL_IDLE_STATUS;
|
||||||
|
|
||||||
|
WiFiUDP Udp;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(REED_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_NO_SHIELD) {
|
||||||
|
Serial.println("No WiFI shield present");
|
||||||
|
// TODO: Create noShieldLoop with visual indication.
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
// TODO: Visually indicate that we are trying to connect
|
||||||
|
Serial.print("Connecting to SSID: ");
|
||||||
|
Serial.println(SSID);
|
||||||
|
status = WiFi.begin(SSID, PASSWORD);
|
||||||
|
|
||||||
|
if (status == WL_CONNECTED) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Visually indicate that we waiting for trying to connect again
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
printNetworkInfo();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int reed_state = digitalRead(REED_PIN);
|
||||||
|
|
||||||
|
int packetSize = Udp.readPacket();
|
||||||
|
if (packetSize) {
|
||||||
|
Udp.beginPacket(udp.remoteIP(), Udp.remotePort());
|
||||||
|
|
||||||
|
if (reed_state == HIGH) {
|
||||||
|
Udp.write(CLOSED);
|
||||||
|
} else {
|
||||||
|
Udp.write(OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
Udp.endPacket();
|
||||||
|
}
|
||||||
|
// TODO: Visually indicate open/closed state.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printNetworkInfo() {
|
||||||
|
|
||||||
|
Serial.print("Connect to WiFi");
|
||||||
|
|
||||||
|
IPAddress ip = WiFi.localIP();
|
||||||
|
Serial.print("IP Address: ");
|
||||||
|
Serial.println(ip);
|
||||||
|
|
||||||
|
byte mac[6];
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
Serial.print("MAC address: ");
|
||||||
|
for (int i = 5; i >= 0; --i) {
|
||||||
|
if (mac[i] < 16) {
|
||||||
|
Serial.print("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(mac[i], HEX);
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
Serial.print(":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue