elektronik:nodemcu_esp8266_erste_schritte
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende ÜberarbeitungNächste ÜberarbeitungBeide Seiten der Revision | ||
elektronik:nodemcu_esp8266_erste_schritte [2019/01/25 00:34] – [Genereller Ablauf] gpipperr | elektronik:nodemcu_esp8266_erste_schritte [2019/01/25 20:16] – [Erste Schritte mit dem ESP8266 / NodeMCU Board mit Lua] gpipperr | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | =====Erste Schritte mit dem ESP8266 / NodeMCU Board mit Lua ===== | + | =====Erste Schritte mit dem ESP8266 / NodeMCU Board mit Lua - Temperatur und Luftfeuchtigkeit messen===== |
<fc # | <fc # | ||
Zeile 459: | Zeile 459: | ||
-- Konfig Tabelle für den Zugriff | -- Konfig Tabelle für den Zugriff | ||
station_cfg={} | station_cfg={} | ||
- | station_cfg.ssid=" | + | --station_cfg.ssid=" |
- | station_cfg.pwd=" | + | --station_cfg.pwd=" |
+ | |||
+ | station_cfg.ssid=" | ||
+ | station_cfg.pwd=" | ||
-- Konfig nicht im Flash speichern | -- Konfig nicht im Flash speichern | ||
Zeile 474: | Zeile 478: | ||
-- | -- | ||
-- Single shot sync time with a server on the local network. | -- Single shot sync time with a server on the local network. | ||
- | sntp.sync(" | + | |
- | function(sec, | + | |
- | print(' | + | |
- | end, | + | |
- | function() | + | |
- | | + | |
- | end | + | |
- | ) | + | |
-- im ersten Schritt einfach setzen .-) | -- im ersten Schritt einfach setzen .-) | ||
- | rtctime.set(1547585804, 0) | + | --rtctime.set(1548237072, 0) |
-- je 1000 ms warten und prüfen | -- je 1000 ms warten und prüfen | ||
- | tmr.alarm(1, | + | tmr.alarm(1, |
-- prüfe ob die Verbindung schon geklappt hat | -- prüfe ob die Verbindung schon geklappt hat | ||
if wifi.sta.getip() == nil then | if wifi.sta.getip() == nil then | ||
print(" | print(" | ||
else | else | ||
+ | |||
+ | ip, nm,gateway = wifi.sta.getip() | ||
-- Konfiguration ausgeben | -- Konfiguration ausgeben | ||
| | ||
| | ||
- | | + | |
+ | | ||
+ | | ||
+ | -- configure Sensor | ||
+ | dofile (" | ||
-- Timer stop | -- Timer stop | ||
| | ||
Zeile 503: | Zeile 506: | ||
end | end | ||
end) | end) | ||
+ | ------------- | ||
- | tmr.alarm(2, 5000, 1, function() | + | -- je 1000 ms warten und prüfen |
+ | -- Uhrzeit setzen beim start | ||
+ | -- Time dann auf 1h setzen, dann wieder Uhrzeit neu setzen | ||
+ | |||
+ | |||
+ | ntptimer =tmr.create() | ||
+ | ntptimer: | ||
-- prüfe ob die Verbindung schon geklappt hat | -- prüfe ob die Verbindung schon geklappt hat | ||
if wifi.sta.getip() == nil then | if wifi.sta.getip() == nil then | ||
- | print(" | + | print(" |
else | else | ||
- | -- rufe die eigentliche Logik auf | + | |
- | | + | -- in my configuration the gateway has ntp feature on |
+ | ip, nm,gateway = wifi.sta.getip() | ||
+ | sntp.sync(gateway, | ||
+ | function(sec, | ||
+ | print(' | ||
+ | rtctime.set(sec, | ||
+ | end, | ||
+ | function() | ||
+ | | ||
+ | end | ||
+ | ) | ||
+ | |||
+ | -- get the time | ||
+ | sec, usec, rate = rtctime.get() | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | -- set the time time to one hour | ||
+ | ntptimer: | ||
+ | |||
+ | |||
+ | end | ||
+ | end) | ||
+ | |||
+ | ntptimer: | ||
+ | |||
+ | |||
+ | --------------------------------- | ||
+ | --- Eigentliche Ausleselogik aufrufen | ||
+ | |||
+ | tmr.alarm(3, | ||
+ | -- prüfe ob die Verbindung schon geklappt hat | ||
+ | if wifi.sta.getip() == nil then | ||
+ | print(" | ||
+ | | ||
+ | print(" | ||
+ | -- get the time | ||
+ | sec, usec, rate = rtctime.get() | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | | ||
+ | |||
+ | humi, temp = am2320.read() | ||
+ | humi=humi/ | ||
+ | temp=temp / 10; | ||
+ | print(string.format(" | ||
+ | print(string.format(" | ||
+ | |||
+ | -- oder alternativ für den DHT22 | ||
+ | -- | ||
+ | -- | ||
+ | |||
+ | |||
| | ||
- | --print(temp) | + | |
end | end | ||
+ | end) | ||
+ | |||
+ | -------------------- | ||
end) | end) | ||
</ | </ | ||
Zeile 659: | Zeile 725: | ||
---- | ---- | ||
+ | |||
+ | ==== Impluse auswerten ==== | ||
+ | |||
+ | Flowmeter angeschloßen | ||
+ | |||
+ | * Schwarz and GND | ||
+ | * Rot and 3,3V | ||
+ | * Gelb an D1 | ||
+ | |||
+ | |||
+ | D0 wird nicht unterstützt für Interrupts! | ||
+ | |||
+ | |||
+ | Impulse pro Minute und Sekunde zählen: | ||
+ | <code lua> | ||
+ | -- Welcher GPIO Port | ||
+ | trigger_pin=1 | ||
+ | |||
+ | -- Zähler | ||
+ | min_time=0 | ||
+ | pulszaehler=0 | ||
+ | pulszaehler_min=0 | ||
+ | |||
+ | |||
+ | ------------------------------------------- | ||
+ | -- Was soll aufgerufen werden | ||
+ | function intPin1(level, | ||
+ | |||
+ | pulszaehler=pulszaehler+1 | ||
+ | | ||
+ | end | ||
+ | |||
+ | ------------------------------------------- | ||
+ | -- Trigger Mode setzen | ||
+ | gpio.mode(trigger_pin, | ||
+ | |||
+ | ------------------------------------------- | ||
+ | -- Interrupt Handler definieren | ||
+ | -- für fallende flanke | ||
+ | gpio.trig(trigger_pin, | ||
+ | |||
+ | ------------------------------------------- | ||
+ | -- je Sekunde den aktuellen Status ausgeben | ||
+ | sectimer =tmr.create() | ||
+ | sectimer: | ||
+ | |||
+ | if min_time == 59 then | ||
+ | min_time=0 | ||
+ | print(string.format(' | ||
+ | pulszaehler_min=0 | ||
+ | -- hier wird der gezählte Werte nun an die Datenbank übergeben | ||
+ | -- send data aufrufen | ||
+ | -- möglichst in einen neuen Thread !! | ||
+ | else | ||
+ | min_time=min_time+1 | ||
+ | end | ||
+ | |||
+ | pulszaehler_min=pulszaehler_min+pulszaehler | ||
+ | print(string.format(' | ||
+ | pulszaehler=0 | ||
+ | | ||
+ | | ||
+ | end) | ||
+ | |||
+ | sectimer: | ||
+ | |||
+ | ------------------------ | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | So etwas ist evtl. besser mit /Lua-RTOS umsetzbar => https:// | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
==== Hilfsfunktionen==== | ==== Hilfsfunktionen==== |
elektronik/nodemcu_esp8266_erste_schritte.txt · Zuletzt geändert: 2021/12/12 15:34 von gpipperr