/* Simple example for receiving and submitting to Gotify. Modified by cc2.tv. https://github.com/sui77/rc-switch/ */ #include #include #include #include RCSwitch mySwitch = RCSwitch(); void setup() { Serial.begin(9600); Serial.println("\r\nMoin!"); mySwitch.enableReceive(4); wifiInit(); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); } void wifiInit() { WiFi.mode(WIFI_STA); WiFi.begin("SSID","Key"); Serial.print("Verbinde mit WLAN "); int temp = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); temp++; if (temp % 7 == 0) Serial.print("."); if (temp > 100) ESP.restart(); } Serial.println(WiFi.localIP()); } void post(bool status) { HTTPClient http; http.begin("http://gotifyserver:90/message?token=TokenID"); http.addHeader("Content-Type", "application/json"); int httpResponseCode; if (status) { httpResponseCode = http.POST("{\"message\": \"ist offen\",\"title\": \"Tür\",\"priority\": 5}"); digitalWrite(LED_BUILTIN, LOW); } if (!status) { httpResponseCode = http.POST("{\"message\": \"ist zu\",\"title\": \"Tür\"}"); digitalWrite(LED_BUILTIN, HIGH); } if (httpResponseCode>0) { String response = http.getString(); Serial.println(httpResponseCode); Serial.println(response); } else { Serial.print("Error on sending POST: "); Serial.println(httpResponseCode); } http.end(); } void loop() { if (mySwitch.available()) { Serial.print("Received "); Serial.print( mySwitch.getReceivedValue() ); Serial.print(" / "); Serial.print( mySwitch.getReceivedBitlength() ); Serial.print("bit "); Serial.print("Protocol: "); Serial.println( mySwitch.getReceivedProtocol() ); // Post status to gotify if (mySwitch.getReceivedValue() == 4410126) post(1); if (mySwitch.getReceivedValue() == 4410122) post(0); mySwitch.resetAvailable(); delay(1000); } }