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/24 12:50] – [Hardware vorbereiten] gpipperr | elektronik:nodemcu_esp8266_erste_schritte [2019/01/25 00:38] – [Genereller Ablauf] gpipperr | ||
---|---|---|---|
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 559: | Zeile 625: | ||
**am2320**: | **am2320**: | ||
+ | |||
+ | Init: | ||
<code lua> | <code lua> | ||
sda, scl = 2, 1 | sda, scl = 2, 1 | ||
i2c.setup(0, | i2c.setup(0, | ||
- | am2320.setup() | + | model, version, serial = am2320.setup() |
+ | |||
+ | print(" | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | </ | ||
+ | |||
+ | Auslesen: | ||
+ | |||
+ | <code lua> | ||
tmr.alarm(4, | tmr.alarm(4, | ||
Zeile 578: | Zeile 656: | ||
</ | </ | ||
+ | |||
=== Daten direkt in die InfluxDB Schreiben === | === Daten direkt in die InfluxDB Schreiben === | ||
Zeile 681: | Zeile 760: | ||
==== Doku und Material zum Thema ==== | ==== Doku und Material zum Thema ==== | ||
+ | NodeMCU Lua Doku => https:// | ||
elektronik/nodemcu_esp8266_erste_schritte.txt · Zuletzt geändert: 2021/12/12 15:34 von gpipperr