diff --git a/source/client/esp32-s3/statusclient/certs.template b/source/client/esp32-s3/statusclient/certs.template deleted file mode 100644 index df8b415..0000000 --- a/source/client/esp32-s3/statusclient/certs.template +++ /dev/null @@ -1,27 +0,0 @@ -/* - * file: certs.template - * desc: This file is part of the Krautspace Doorstatus project. It contains - * certificates for the statusclient.ino programm, that runs on an esp32-s3 - * board (esp32-1732s019). - * - * Replace the comments in certificate sections with our own certificates. - */ - -constexpr static inline char const CA_CERTS[] PROGMEM = R"EOF( ------BEGIN CERTIFICATE----- -place here your servers public cert ------END CERTIFICATE----- -)EOF"; - -constexpr static inline char const CLIENT_CERT[] PROGMEM = R"EOF( ------BEGIN CERTIFICATE----- -place here your clients public dert ------END CERTIFICATE----- -)EOF"; - -constexpr static inline char const CLIENT_KEY[] PROGMEM = R"EOF( ------BEGIN RSA PRIVATE KEY----- -place here your clients private key ------END RSA PRIVATE KEY----- -)EOF"; - diff --git a/source/client/esp32-s3/statusclient/config.template b/source/client/esp32-s3/statusclient/config.template deleted file mode 100644 index e2a3bc3..0000000 --- a/source/client/esp32-s3/statusclient/config.template +++ /dev/null @@ -1,33 +0,0 @@ -/* - * file: config.h - */ - -/* endpoint */ -const char* SERVER_URL = "your status server url"; -const uint16_t SERVER_PORT = port; - -/* ssl debud level - * esp_ssl_debug_none = 0 - * esp_ssl_debug_error = 1 - * esp_ssl_debug_warn = 2 - * esp_ssl_debug_info = 3 - * esp_ssl_debug_dump = 4 - */ -const uint8_t SSL_DEBUG_LEVEL = 3; - -/* ssl socket */ -const int32_t TIMEOUT = 20; -const int32_t SESSION_TIMEOUT = 6000; - -/* serial interface settings */ -const unsigned long BAUD_RATE = 115200; - -/* pin and frequence to read the pin */ -int REED_PIN = 47; -const unsigned long FREQUENCY = 3000; - -/* time server settings */ -const char* NTP_URL = "pool.ntp.org"; -const int GTM_OFFSET_SEC = 3600; -const unsigned long DAYLIGHT_OFFSET_SEC = 3600; - diff --git a/source/client/esp32-s3/statusclient/credentials.template b/source/client/esp32-s3/statusclient/credentials.template deleted file mode 100644 index e419d7c..0000000 --- a/source/client/esp32-s3/statusclient/credentials.template +++ /dev/null @@ -1,3 +0,0 @@ -const char *WIFI_SSID = "ssid meines wifi"; -const char *WIFI_PASSWORD = "passwort meines wifi"; - diff --git a/source/client/esp32-s3/statusclient/statusclient.ino b/source/client/esp32-s3/statusclient/statusclient.ino deleted file mode 100644 index a6b8bb0..0000000 --- a/source/client/esp32-s3/statusclient/statusclient.ino +++ /dev/null @@ -1,188 +0,0 @@ -/** - * - */ -#include -#include -#include -#include -#include "config.h" -#include "certs.h" -#include "credentials.h" - - -enum door_state { - /* - */ - CLOSED = '0', - OPEN = '1' -}; -door_state new_door_state = CLOSED; -door_state current_door_state = CLOSED; -WiFiClient basic_client; -ESP_SSLClient ssl_client; - - -void display_info() { - /* - * ausgabe einiger infos tum device. ich verstehe allerdings die - * for-schleife nicht. - */ - uint32_t chipId = 0; - - for (int i = 0; i < 17; i = i + 8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - Serial.printf("\nESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), - ESP.getChipRevision()); - Serial.printf("This chip has %d cores\n", ESP.getChipCores()); - Serial.print("Chip ID: "); - Serial.println(chipId); - Serial.print(" "); -} - -void init_wifi() { - /* - */ - int counter = 0; - Serial.print("Connecting to wifi "); - Serial.print(WIFI_SSID); - WiFi.mode(WIFI_STA); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - Serial.print("."); - counter++; - if (counter >= 180) { - Serial.println(" Failed"); - ESP.restart(); - } - } - Serial.println(" Connected"); - Serial.print("IP: "); - Serial.println(WiFi.localIP()); - Serial.print("Strength: "); - Serial.println(WiFi.RSSI()); -} - -void set_clock() { - /* - * We need time for certificate authorization - */ - Serial.print("Fetch time from "); - Serial.println(NTP_URL); - configTime(GTM_OFFSET_SEC, DAYLIGHT_OFFSET_SEC, NTP_URL); - printLocalTime(); -} - -void printLocalTime() { - /* - */ - struct tm timeinfo; - if (!getLocalTime(&timeinfo)) { - Serial.println("Failed to obtain time"); - return; - } - Serial.printf("%s\n", asctime(&timeinfo)); -} - -void set_ssl() { - /* - */ - // ssl_client.setTimeout(120); - // ssl_client.setSessionTimeout(0); - ssl_client.setDebugLevel(SSL_DEBUG_LEVEL); - ssl_client.setClient(&basic_client, false); - ssl_client.setSSLVersion(BR_TLS12, BR_TLS12); - ssl_client.setCACert(CA_CERTS); - ssl_client.setCertificate(CLIENT_CERT); - ssl_client.setPrivateKey(CLIENT_KEY); - -} - -door_state read_door_state() { - /* - * die initialisierung des reed-switch-pins mit pullup bewirkt, dass am pin - * 3,3 volt anliegen. die verbindung des pins mit GND sorgt dafür, - * dass die spannung "abfließen" kann. dadurch hat der pin dann den - * status 'low'. die option geht leider nur mit der bibliothek für den - * esp8862. - * geschlossene tür -> reed geschlossen -> low - * geöffnete tür -> reed offen -> high - */ - if (digitalRead(REED_PIN) == HIGH) { - return OPEN; - } - return CLOSED; -} - -bool send_status(door_state state) { - /* - * param 1: door_state - * returns: boolean - * - * needs error handling - */ - int32_t response = 0; - int counter = 0; - - // connect to server - Serial.print("Connecting to server "); - Serial.print(SERVER_URL); - Serial.print(" ... "); - if (ssl_client.connect(SERVER_URL, SERVER_PORT)) { - Serial.println(" ok"); - Serial.print("Upgrade to HTTPS..."); - if (!ssl_client.connectSSL()) - { - Serial.println(" failed\r\n"); - return false; - } - Serial.println(" ok"); - // send new status - Serial.print("Send new status ... "); - response = ssl_client.write(current_door_state); - ssl_client.flush(); - Serial.print("Bytes written: "); - Serial.println(response); - - Serial.print("Read response..."); - Serial.print((char)ssl_client.read()); - Serial.println(); - } else { - Serial.println(" failed\n"); - ssl_client.stop(); - return false; - } - ssl_client.stop(); - return true; -} - -void setup() { - /* - */ - Serial.begin(115200); - Serial.println("------------- setup -------------"); - display_info(); - init_wifi(); - set_clock(); - set_ssl(); - Serial.println("-------- setup finished ---------"); -} - -void loop() { - /* - */ - new_door_state = read_door_state(); - if (new_door_state != current_door_state) { - Serial.print("Status has changed to "); - Serial.println(new_door_state); - if (send_status(new_door_state)) { - current_door_state = new_door_state; - Serial.println("Door status send successful"); - } else { - Serial.println("Failed to send new door status"); - } - } - delay(FREQUENCY); -} diff --git a/source/client/nodemcu/statusclient/statusclient.ino b/source/client/nodemcu/statusclient/statusclient.ino index e49fa21..cfe7164 100644 --- a/source/client/nodemcu/statusclient/statusclient.ino +++ b/source/client/nodemcu/statusclient/statusclient.ino @@ -22,8 +22,10 @@ namespace cpp23 { // defining some constants enum : uint8_t { - LED_PIN = 16, // D0 - GPIO 16 - REED_PIN = 2 // D4 - GPIO 2 + LED_PIN = 16, // D0 + //REED_PIN = 5 // D1 + REED_PIN = 2 // D4 + }; enum class door_state { diff --git a/source/server/api_template b/source/server/api_template new file mode 100644 index 0000000..2e230db --- /dev/null +++ b/source/server/api_template @@ -0,0 +1,38 @@ +{ + "api":"0.13", + "space":"Krautspace", + "url":"https://kraut.space", + "logo":"https://status.krautspace.de/images/krautspace_pixelbanner.png", + "location":{ + "address":"Hackspace Jena e. V., Krautgasse 26, 07743 Jena, Germany", + "lat":50.9292, + "lon":11.5826 + }, + "state":{ + "open":false, + "lastchange":1563499131, + "icon":{ + "open":"https://status.krautspace.de/images/krautspace_pixelicon_open.png", + "closed":"https://status.krautspace.de/images/krautspace_pixelicon_closed.png" + } + }, + "feeds":{ + "calendar":{ + "type":"ical", + "url":"https://calcifer.datenknoten.me/tags/krautspace.ics" + } + }, + "contact":{ + "twitter":"@HackspaceJena", + "quitter":"@Krautspace", + "facebook":"https://www.facebook.com/HackspaceJena", + "email":"office@krautspace.de" + }, + "issue_report_channels":[ + "twitter", + "email" + ], + "projects":[ + "https://github.com/HackspaceJena/" + ] +} diff --git a/source/server/apistatusd.py b/source/server/apistatusd.py index facdadc..5ec3b68 100755 --- a/source/server/apistatusd.py +++ b/source/server/apistatusd.py @@ -367,6 +367,7 @@ def main(): "matrix": "#krautchan:matrix.kraut.space" }, "issue_report_channels": [ + "matrix", "email" ], "projects": [