Hallo,
jetzt möchte ich auch mal meine Lösung zeigen.
Das ganze ist relativ selbst erklärend.
Mir ging es darum, dass es nicht viel Strom braucht und mit Batterien läuft.
Darum wurde auch ein Wemos D1 Mini Lite verwendend, der im deepsleep mode gerade mal 0,04 mA verbraucht.
Die Schaltung funktioniert auf jeden fall mit einem 8VDC Klingel Trafo, 12VDC sollten auch gehen.
Meinungen von euch erwünscht.
Schaltplan:
Adruino Code:
Code
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
extern "C" {
#include <user_interface.h>
}
// ******* Netzwerkeinstellungen, bitte anpassen! *******
const char* ssid = "SSID"; // SSID des vorhandenen WLANs
const char* password = "Passwort"; // Passwort für das vorhandene WLAN
// ******* MQTT Config, bitte anpassen! *******
const char* mqtt_server = "192.168.0.0";
const char* mqtt_port = "1883";
const char* mqtt_user = "Username";
const char* mqtt_password = "Passwort";
WiFiClient espClient;
PubSubClient client(espClient);
int batterie() {
pinMode(A0, INPUT);
int value = analogRead(A0);
int Percent = map(value, 600, 1023, 0, 100);
if ( Percent < 0 ) { Percent = 0; }
if ( Percent > 100 ) { Percent = 100; }
return Percent;
}
uint8_t rssiToPercentage(int32_t rssi) {
uint8_t quality;
if (rssi <= -100) {
quality = 0;
} else if (rssi >= -50) {
quality = 100;
} else {
quality = 2 * (rssi + 100);
}
return quality;
}
void setup() {
// Seriellen Monitor für Kontrollausgaben öffnen
Serial.begin(9600);
Serial.println("");
Serial.println("Türklingel");
// WLAN-Verbindung herstellen
WiFi.begin(ssid, password);
Serial.print("Verbindungsaufbau");
// Verbindungsaufbau abwarten
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// MQTT Verbindung herstellen
client.setServer(mqtt_server, mqtt_port);
client.connect("Türklingel", mqtt_user, mqtt_password);
rst_info *rinfo;
rinfo = ESP.getResetInfoPtr();
// Nur auslösen bei Reset
if (String((*rinfo).reason) == "5")
{
client.publish("Türklingel/trigger", "true");
}
char bpro[50];
sprintf(bpro, "%d", batterie());
client.publish("Türklingel/batterieprozent", bpro);
pinMode(A0, INPUT);
int axvalue = analogRead(A0);
char bval[50];
sprintf(bval, "%d", axvalue);
client.publish("Türklingel/batteriewert", bval);
char sst[50];
sprintf(sst, "%d", rssiToPercentage(WiFi.RSSI()));
client.publish("Türklingel/signalstärke", sst);
char buf[16];
const IPAddress& ip = WiFi.localIP();
snprintf(buf, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
client.publish("Türklingel/ipadresse", buf);
delay(1000);
WiFi.mode(WIFI_OFF);
ESP.deepSleep(0);
}
void loop() {
}
Alles anzeigen
Blockly Script:
Code
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="on" id="#!{jE.8hAaEE9F+d8HT6" x="113" y="38">
<field name="OID">mqtt.0.Türklingel.trigger</field>
<field name="CONDITION">true</field>
<field name="ACK_CONDITION"></field>
<statement name="STATEMENT">
<block type="telegram" id="dU*kBnuQ)HkiH0?n8Dqk">
<field name="INSTANCE"></field>
<field name="LOG"></field>
<field name="SILENT">FALSE</field>
<field name="PARSEMODE">default</field>
<value name="MESSAGE">
<shadow type="text" id="16ht-^V){^u7FfVDgbUR">
<field name="TEXT">Es hat an der Tür geklingelt</field>
</shadow>
</value>
<next>
<block type="update" id="5`|V/RA03L?6**FjoV5}">
<mutation delay_input="false"></mutation>
<field name="OID">mqtt.0.Türklingel.trigger</field>
<field name="WITH_DELAY">FALSE</field>
<value name="VALUE">
<block type="text" id="h.3^l*n#JS)DFaTg^;RN">
<field name="TEXT">false</field>
</block>
</value>
</block>
</next>
</block>
</statement>
<next>
<block type="on" id="(azr(q+XWV1}?pZb-Ow[">
<field name="OID">mqtt.0.Türklingel.batterieprozent</field>
<field name="CONDITION">ne</field>
<field name="ACK_CONDITION"></field>
<statement name="STATEMENT">
<block type="controls_if" id="p6{y~MZ[HvDWw%W*=bbv">
<value name="IF0">
<block type="logic_compare" id="|-xwh]b+T|YWl6HQO(b1">
<field name="OP">LTE</field>
<value name="A">
<block type="get_value" id="H609]}0L[KJ}b;3(zTyX">
<field name="ATTR">val</field>
<field name="OID">mqtt.0.Türklingel.batterieprozent</field>
</block>
</value>
<value name="B">
<block type="text" id="Z[n8|bXPUdD]ThA+b}RH">
<field name="TEXT">10</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="telegram" id="RH_R(@P#|v_L%67X;%BP">
<field name="INSTANCE"></field>
<field name="LOG"></field>
<field name="SILENT">FALSE</field>
<field name="PARSEMODE">default</field>
<value name="MESSAGE">
<shadow type="text" id="?.ZA6F?9UOwlxms5/G;l">
<field name="TEXT">text</field>
</shadow>
<block type="text_join" id="UQ6n?QPD^4FBjz;R6Hh:">
<mutation items="3"></mutation>
<value name="ADD0">
<block type="text" id="mQhu(.K^B*lFuBRowSo1">
<field name="TEXT">Achtung! Die Batterie der Türklingel hat nur noch </field>
</block>
</value>
<value name="ADD1">
<block type="get_value" id="MRKq#,N`#JU+?(.=9{m,">
<field name="ATTR">val</field>
<field name="OID">mqtt.0.Türklingel.batterieprozent</field>
</block>
</value>
<value name="ADD2">
<block type="text" id="?iE0w0[_vq`[XvGz*of]">
<field name="TEXT">%</field>
</block>
</value>
</block>
</value>
</block>
</statement>
</block>
</statement>
</block>
</next>
</block>
</xml>
Alles anzeigen