ESP8266 schickt Temperatur an SHC

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • RE: ESP8266 schickt Temperatur an SHC

    Hallo

    Bin gerade beim Flashen, ESP wurde in NodeMCU erkannt.
    Com4 Baut 9600 eingestellt.

    Gpio 0 ist an Gnd, CH_PD pin von VCC kurz gelöst.
    Auf Flash gedrückt, unter der Stausleiste erscheint rythmisch
    require wifi , aber weiter passiert nichts.
    Muss ich denn die .bin Datei eingeben, oder holt das programm sich
    die .bin Datei selber.

    Im Log steht:

    Quellcode

    1. Note:Detect serial port changed.
    2. Note:Auto MAP serial port.Port-->COM4
    3. Note:Serial port connected.
    4. Note:Begin find ESP8266.
    5. Note:Serial port disconnected.
    6. Warning:Serial port closed by user.
    7. Note:Detect serial port changed.
    8. Note:Auto MAP serial port.Port-->COM1
    9. Note:Detect serial port changed.
    10. Note:Auto MAP serial port.Port-->COM4
    11. Note:Serial port connected.
    12. Note:Begin find ESP8266.
    Alles anzeigen

    [hr]

    Ok, Fehler gefunden.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von premo ()

  • RE: ESP8266 schickt Temperatur an SHC

    Habe mal versucht die Firmware zuflashen und die Lua aufzuspielen.
    Als Laie nicht einfach.  :-/
    Leider hatte ich keinen Erfolg.

    Welche Firmware ist denn die richtige, ich habe diese genommen
    "nodemcu_20150216".

    Mit Esplorer habe ich die "ds18b20.lua" aufgespielt

    Brainfuck-Quellcode

    1. --------------------------------------------------------------------------------
    2. -- DS18B20 one wire module for NODEMCU
    3. -- NODEMCU TEAM
    4. -- LICENCE: http://opensource.org/licenses/MIT
    5. -- Vowstar <vowstar@nodemcu.com>
    6. -- 2015/02/14 sza2 <sza2trash@gmail.com> Fix for negative values
    7. --------------------------------------------------------------------------------
    8. -- Set module name as parameter of require
    9. local modname = ...
    10. local M = {}
    11. _G[modname] = M
    12. --------------------------------------------------------------------------------
    13. -- Local used variables
    14. --------------------------------------------------------------------------------
    15. -- DS18B20 dq pin
    16. local pin = nil
    17. -- DS18B20 default pin
    18. local defaultPin = 4
    19. --------------------------------------------------------------------------------
    20. -- Local used modules
    21. --------------------------------------------------------------------------------
    22. -- Table module
    23. local table = table
    24. -- String module
    25. local string = string
    26. -- One wire module
    27. local ow = ow
    28. -- Timer module
    29. local tmr = tmr
    30. -- Limited to local environment
    31. setfenv(1,M)
    32. --------------------------------------------------------------------------------
    33. -- Implementation
    34. --------------------------------------------------------------------------------
    35. C = 0
    36. F = 1
    37. K = 2
    38. function setup(dq)
    39. pin = dq
    40. if(pin == nil) then
    41.   pin = defaultPin
    42. end
    43. ow.setup(pin)
    44. end
    45. function addrs()
    46. setup(pin)
    47. tbl = {}
    48. ow.reset_search(pin)
    49. repeat
    50.   addr = ow.search(pin)
    51.   if(addr ~= nil) then
    52.     table.insert(tbl, addr)
    53.   end
    54.   tmr.wdclr()
    55. until (addr == nil)
    56. ow.reset_search(pin)
    57. return tbl
    58. end
    59. function readNumber(addr, unit)
    60. result = nil
    61. setup(pin)
    62. flag = false
    63. if(addr == nil) then
    64.   ow.reset_search(pin)
    65.   count = 0
    66.   repeat
    67.     count = count + 1
    68.     addr = ow.search(pin)
    69.     tmr.wdclr()
    70.   until((addr ~= nil) or (count > 100))
    71.   ow.reset_search(pin)
    72. end
    73. if(addr == nil) then
    74.   return result
    75. end
    76. crc = ow.crc8(string.sub(addr,1,7))
    77. if (crc == addr:byte(8)) then
    78.   if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
    79.     -- print("Device is a DS18S20 family device.")
    80.     ow.reset(pin)
    81.     ow.select(pin, addr)
    82.     ow.write(pin, 0x44, 1)
    83.     -- tmr.delay(1000000)
    84.     present = ow.reset(pin)
    85.     ow.select(pin, addr)
    86.     ow.write(pin,0xBE,1)
    87.     --print("P="..present)
    88.     data = nil
    89.     data = string.char(ow.read(pin))
    90.     for i = 1, 8 do
    91.       data = data .. string.char(ow.read(pin))
    92.     end
    93.     -- print(data:byte(1,9))
    94.     crc = ow.crc8(string.sub(data,1,8))
    95.     -- print("CRC="..crc)
    96.     if (crc == data:byte(9)) then
    97.       t = (data:byte(1) + data:byte(2) * 256)
    98.       if (t > 32767) then
    99.         t = t - 65536
    100.       end
    101.    
    102.       if(unit == nil or unit == C) then
    103.         t = t * 625
    104.       elseif(unit == F) then
    105.         t = t * 1125 + 320000
    106.       elseif(unit == K) then
    107.         t = t * 625 + 2731500
    108.       else
    109.         return nil
    110.       end
    111.       --print("temp1:" ..t.. "next")
    112.       t = t / 1
    113.       --print("temp2/10000:" ..t.. "next")
    114.      
    115.       --print("Temperature="..t1.."."..t2.." Centigrade")
    116.       -- result = t1.."."..t2
    117.       return t
    118.     end
    119.     tmr.wdclr()
    120.   else
    121.   -- print("Device family is not recognized.")
    122.   end
    123. else
    124. -- print("CRC is not valid!")
    125. end
    126. return result
    127. end
    128. function read(addr, unit)
    129. t = readNumber(addr, unit)
    130. if (t == nil) then
    131.   return nil
    132. else
    133.   return t
    134. end
    135. end
    136. -- Return module table
    137. return M
    Alles anzeigen


    und anschliessend noch die angepasste "ds18b20 daten an shc zu senden"

    Brainfuck-Quellcode

    1. print("init.lua Start... v.0.20")
    2. ---------------------------------
    3. function read_temp()
    4. sensor = require("ds18b20")
    5. ---------------------------------
    6. -- Sensor pin (nodemcu I/O Index)
    7. sensorPin = 3
    8. -- Sensor Initialisieren
    9. sensor.setup(sensorPin)
    10. -- Temperatur auslesen und ausgeben ggf anpassung für kommastelle
    11.   temperatur = sensor.read()
    12.   t1 = string.sub(temperatur,1,2)
    13.   t2 = string.sub(temperatur,3,7)
    14.   return temperatur,t1,t2
    15. end
    16. ---------------------------------------
    17. function send_to_shc()
    18. print("Sending data to shc...")
    19. read_temp()
    20. --print("temp:" ..temperatur.. "\n")
    21. conn=net.createConnection(net.TCP, 0)
    22. conn:on("receive", function(conn, payload) print(payload) end)
    23. -- senden an shc
    24. conn:connect(80,"192.168.178.38") <--- SHC ip anpassen
    25. conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=26&sid=28-0315515793ff&type=1&v1=" ..t1.. "." ..t2.. " HTTP/1.1\r\n") <-- ggf pfad anpassen und sid anpassen
    26. conn:send("Host: 192.168.178.38\r\n")  <-- SHC ip anpassen
    27. conn:send("Accept: */*\r\n")
    28. conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
    29. conn:send("\r\n")
    30. conn:on("sent",function(conn)
    31.                     --print("Closing connection")
    32.                     conn:close()
    33.                     print("daten an shc gesendet" ..t1.. "." ..t2.. "\n")
    34.                 end)
    35. conn:on("disconnection", function(conn)
    36.                               print("Got disconnection...")
    37.                               --print("error...")
    38. end)
    39. end
    40. -----------------------------------------------
    41. -- STA Modus
    42. wifi.setmode(wifi.STATION)
    43. -- SSID, Passwort
    44. wifi.sta.config("Fritz Repeater 2", "937...48")  <-- WLAN DATEN anpassen
    45. ---------------------------------
    46. -- Statische IP
    47. wifi.sta.setip({ip="192.168.178.3",netmask="255.255.255.0",gateway="192.168.178.1"}) <- um dem ganzen eine feste ip zugeben
    48. print(wifi.sta.getip())
    49. read_temp()
    50. send_to_shc()
    51. --print("Temperature: "..t1.. "." ..t2.. "'C")
    52. --- alle 30sek an shc senden
    53. tmr.alarm(0, 30000, 1, function()
    54. send_to_shc()
    55. end)
    Alles anzeigen
  • RE: ESP8266 schickt Temperatur an SHC

    hey, also ich habe die nodemcu firmware genommen die standart mäsig im ESP8266Flasher eingestellt war

    wenn das erflogreich geklappt hat bei dir und du anschliesend

    den esplorer öffnets und den richtigen com port einstellst dann sollte dort sowas :

    bBÊǦÿSbCÿÎÎJÄäÎÆJ¤×Φêø

    NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
    .....


    erscheinen


    WICHTIG im ESP8266Flasher baudrate 115200 einstellen ( je nach chip version ) und im ESPlorer später dann 9600!

    und für den esplorer gpio0 zu gnd wieder entfernen!
  • RE: ESP8266 schickt Temperatur an SHC

    So, habe jetzt nochmal die Firmware die im Flashtool eingestellt ist genommen.
    Vorher die Bautrate auf 115200 eingestellt (flashvorgang geht jetzt schneller).

    Im Wlan Netzwerk wird der ESP als "AI-Thinker_A54B8A" erkannt.


    Im Esplorer wieder Bautrate auf 9600 gestellt.

    Als 1. Lua habe ich die oben im #10 genommen "ds18b20.lua".

    Dann als 2. Lua die "um ds18b20 daten an shc zu senden".

    In der 2. habe folgende Daten geändert:

    Quellcode

    1. conn:connect(80,"192.168.0.15") <--- SHC ip anpassen  192.168.178.38 (feste IP vom
    2. RPi)
    3. conn:send("Host: 192.168.0.15\r\n")  <-- SHC ip anpassen   Auch 192.168.178.38
    4. conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=26&sid=28-
    5. 0315515793ff&type=1&v1=" ..t1.. "." ..t2.. " HTTP/1.1\r\n") <-- ggf pfad anpassen
    6. und sid anpassen  Nichts verändert
    7. wifi.sta.config("SSID", "wlanpassword")  <-- WLAN DATEN anpassen  Daten vom Fritz
    8. Repeater genommen
    9. wifi.sta.setip({ip="192.168.0.210",netmask="255.255.255.0",gateway="192.168.0.1"})
    10. <- um dem ganzen eine feste ip zugeben   Die IP vom Fritz Repeater und gateway von
    11. der Fritzbox
    Alles anzeigen


    Leider ist im SHC 2.2.2 der am Gpio0 angeschlossene DS18 nicht zusehen.
  • RE: ESP8266 schickt Temperatur an SHC

    Habe jetzt mit Esplorer den ESP formatiert und neu mit der entfernten Zeile
    "wifi.sta.setip({ip="192.168.0.126",netmask="255.255.255.0",gateway="192.168.0.1"})"
    Beschrieben.

    Quellcode

    1. PORT OPEN 9600
    2. file.format()
    3. format done.
    4. > FILE="1.DS18theo.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    5. > >> > > > > > > > > > > > > > > >
    6. --Done--
    7. >
    8. >
    9. > FILE="gMaN.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    10. > >> > > > > > > > >
    11. --Done--
    12. >
    13. >
    14. > dofile("gMaN.lua")
    15. nil
    16. gMaN.lua:2: module 'ds18b20' not found:
    17. no field package.preload['ds18b20']
    18. no file 'ds18b20.lc'
    19. no file 'ds18b20.lua'
    20. > 0‚~–4û!‹Y…OI:¶COCE’!†üOCAø
    21. NodeMCU 0.9.5 build 20150318  powered by Lua 5.1.4
    22. lua: cannot open init.lua
    23. >
    Alles anzeigen


    Muss die blaue LED eigentlich aufleuchten oder rythmisch blinken, wenn alles programmiert ist.
    Die rote leuchtet ja konstant.
    Bei mir leuchtet die blaue nur kurz wenn ich die Spannung drauf gebe.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von premo ()

  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:


    Habe jetzt mit Esplorer den ESP formatiert und neu mit der entfernten Zeile
    "wifi.sta.setip({ip="192.168.0.126",netmask="255.255.255.0",gateway="192.168.0.1"})"
    Beschrieben.



    Quellcode

    1. PORT OPEN 9600
    2. file.format()
    3. format done.
    4. > FILE="1.DS18theo.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    5. > >> > > > > > > > > > > > > > > >
    6. --Done--
    7. >
    8. >
    9. > FILE="gMaN.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    10. > >> > > > > > > > >
    11. --Done--
    12. >
    13. >
    14. > dofile("gMaN.lua")
    15. nil
    16. gMaN.lua:2: module 'ds18b20' not found:
    17. no field package.preload['ds18b20']
    18. no file 'ds18b20.lc'
    19. no file 'ds18b20.lua'
    20. > 0‚~–4û!‹Y…OI:¶COCE’!†üOCAø
    21. NodeMCU 0.9.5 build 20150318  powered by Lua 5.1.4
    22. lua: cannot open init.lua
    23. >
    Alles anzeigen


    Muss die blaue LED eigentlich aufleuchten oder rythmisch blinken, wenn alles programmiert ist.
    Die rote leuchtet ja konstant.
    Bei mir leuchtet die blaue nur kurz wenn ich die Spannung drauf gebe.

    Hallo, das mit den LED ist ok. Die blaue blinkt nur wenn gesendet wird.
    Aber, wenn das deine aktuelle Ausgabe des ESPlorer ist, hat du gar keine LUA files drauf:

    Quellcode

    1. no file 'ds18b20.lc'
    2. no file 'ds18b20.lua
    3. lua: cannot open init.lua

    Die files von gMaN funktionieren bei meinen ESP8266-01 nicht. Ich habe aus dem FHEM-Forum (Kroonen) lua files übernommen und angepaßt. Funktioniert aber nur mit gpio2. Bei gpio0 starten die ESP bei mir nicht.
    Noch mal der Reihe nach: erst die ds18b20.lua unverändert aufspielen.
    Dann meine shc.lua (mit angepassten IPs) aufspielen. Danach meine init.lua.

    shc.lua

    Quellcode

    1. --shc.lua
    2. require('ds18b20')
    3. -- ESP-01 GPIO Mapping
    4. gpio0 =3
    5. gpio2 =4
    6. ds18b20.setup(gpio2)
    7. t=ds18b20.read()
    8. print("Temp:" .. ds18b20.read() .. " C\n")
    9. if(t==nil) then
    10. t=0
    11. end
    12. tmr.alarm(0,120000, 1, function()
    13. t=ds18b20.read()
    14. conn=net.createConnection(net.TCP, 0)
    15. conn:on("receive", function(conn, payload) print(payload) end )
    16. conn:connect(80,"192.168.xxx.xxx")
    17.  conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=27&sid=28-0315515795ff&type=1&v1=" ..t.. " HTTP/1.1\r\n")
    18. conn:send("Host: 192.168.xxx.xxx\r\n")
    19. conn:send("Accept: */*\r\n")
    20. conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
    21. conn:send("\r\n")
    22. conn:on("sent",function(conn)
    23.                     --print("Closing connection")
    24.                     conn:close()
    25.                     print("daten an shc gesendet" ..t.. "\n")
    26.                 end)
    27. conn:on("disconnection", function(conn)
    28.                               print("Got disconnection...")
    29.                               --print("error...")
    30. end)
    31. end)
    Alles anzeigen


    init.lua:


    Quellcode

    1. --init.lua
    2. wifi.setmode(wifi.STATION)
    3. wifi.sta.config("dein_wlan_Name","Dein_WLAN_Passwort")
    4. wifi.sta.setip({ip="192.168.xxx.xxx",netmask="255.255.255.0",gateway="192.168.xxx.xxx"})
    5. print(wifi.sta.getip())
    6. wifi.sta.connect()
    7. tmr.alarm(1, 10000, 1, function()
    8.  if wifi.sta.getip()== nil then
    9.  print("IP unavaiable, Waiting...")
    10. else
    11.  tmr.stop(1)
    12. print("ESP8266 mode is: " .. wifi.getmode())
    13. print("The module MAC address is: " .. wifi.ap.getmac())
    14. print("Config done, IP is "..wifi.sta.getip())
    15. dofile ("shc.lua")
    16. end
    17. end)
    Alles anzeigen

    Hiermit habe ich drei sensorpoints am laufen.
    Falls der ESP irgendwann sagt no memory (oder so ähnlich) einfach im ESPlorer die ds18b20.lua mit compile 18b20.lua
    to .lc wandeln und dann die .lua löschen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von ganele ()

  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:


    Habe jetzt mit Esplorer den ESP formatiert und neu mit der entfernten Zeile
    "wifi.sta.setip({ip="192.168.0.126",netmask="255.255.255.0",gateway="192.168.0.1"})"
    Beschrieben.


    Quellcode

    1. PORT OPEN 9600
    2. file.format()
    3. format done.
    4. > FILE="[color=#ff3399][b]1.DS18theo.lua[/b][/color]" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    5. > >> > > > > > > > > > > > > > > >
    6. --Done--
    7. >
    8. >
    9. > FILE="gMaN.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
    10. > >> > > > > > > > >
    11. --Done--
    12. >
    13. >
    14. > dofile("gMaN.lua")
    15. nil
    16. gMaN.lua:2: module 'ds18b20' not found:
    17. no field package.preload['ds18b20']
    18. no file 'ds18b20.lc'
    19. no file 'ds18b20.lua'
    20. > 0‚~–4û!‹Y…OI:¶COCE’!†üOCAø
    Alles anzeigen






    gibt der datei mal den namen ds18b20.lua und versuch es dann
  • RE: ESP8266 schickt Temperatur an SHC

    Danke euch, bin jetzt ein ganzes Stück weiter.

    In SHC wurde ein Sensorpoint 27 angelegt.
    Sensor ist sichtbar, aber es wird ein Wert von
    248.750,0 °C angezeigt.

    ESP habe ich 2x aufgesetzt, erkannt wird nur 1x
    in SHC.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von premo ()

  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:


    Danke euch, bin jetzt ein ganzes Stück weiter.

    In SHC wurde ein Sensorpoint 27 angelegt.
    Sensor ist sichtbar, aber es wird ein Wert von
    248.750,0 °C angezeigt.

    ESP habe ich 2x aufgesetzt, erkannt wird nur 1x
    in SHC.


    Hallo, hast du beim zweiten ESP die Sensor-ID geändert?
    Temperatur: ganz schön warm!
    Du hast bestimmt die ds18b20.lua aus #10 genommen?
    Fehlt der Divisor (10000) bei t1, dann passt es.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von ganele ()

  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:


    Danke euch, bin jetzt ein ganzes Stück weiter.

    In SHC wurde ein Sensorpoint 27 angelegt.
    Sensor ist sichtbar, aber es wird ein Wert von
    248.750,0 °C angezeigt.

    ESP habe ich 2x aufgesetzt, erkannt wird nur 1x
    in SHC.



    die sensorpoint id kannst du hier:


    conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=27&sid=28-

    0315515793ff&type=1&v1=" ..t1.. "." ..t2.. " HTTP/1.1\r\n")


    poste bitte noch mal die Debug ausgabe aus dem ESPlorer evtl wird  die richtige temperatur angezeigt und es ist nur ein "umrechnungs" fehler ?
  • RE: ESP8266 schickt Temperatur an SHC

    Der erstellte Sensor Point 28 wird jetzt angezeigt.
    Bei sensor steht "keine Einträge".

    Quellcode

    1. > dofile("init.lua")
    2. 192.168.178.43 255.255.255.0 192.168.178.1
    3. > ESP8266 mode is: 1
    4. The module MAC address is: 1A-FE-34-A2-4A-7E
    5. Config done, IP is 192.168.178.43
    6. Temp:254375 C
    7. daten an shc gesendet254375
    8. Got disconnection...
    9. 0‚~–4û!‹Y…OI:¶COCE’!†üOCAø
    10. NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
    11. 192.168.178.43 255.255.255.0 192.168.178.1
    12. > ESP8266 mode is: 1
    13. The module MAC address is: 1A-FE-34-A2-4A-7E
    14. Config done, IP is 192.168.178.43
    15. Temp:255000 C
    16. daten an shc gesendet258750
    17. Got disconnection...
    18. daten an shc gesendet246875
    19. Got disconnection...
    Alles anzeigen

    [hr]

    ganele schrieb:


    premo schrieb:


    Danke euch, bin jetzt ein ganzes Stück weiter.

    In SHC wurde ein Sensorpoint 27 angelegt.
    Sensor ist sichtbar, aber es wird ein Wert von
    248.750,0 °C angezeigt.

    ESP habe ich 2x aufgesetzt, erkannt wird nur 1x
    in SHC.


    Hallo, hast du beim zweiten ESP die Sensor-ID geändert?
    Temperatur: ganz schön warm!
    Du hast bestimmt die ds18b20.lua aus #10 genommen?
    Fehlt der Divisor (10000) bei t1, dann passt es.


    Ok , habe ich auch gerade festgestellt mit der falschen SID.
    Wo bekomme ich die SID von den mir angeschlossenen Sensoren her.
    ds18b20.lua habe ich aus #10 :-/
    [hr]
    Fehlt der Divisor (10000) bei t1, dann passt es.

    Ist das in der Zeile 115, da steht "t = t / 1"

    Muss das "t = t / 10000" heissen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von premo ()

  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:



    Ok , habe ich auch gerade festgestellt mit der falschen SID.
    Wo bekomme ich die SID von den mir angeschlossenen Sensoren her.
    ds18b20.lua habe ich aus #10 :-/

    [hr]
    Fehlt der Divisor (10000) bei t1, dann passt es.

    Ist das in der Zeile 115, da steht "t = t / 1"

    Muss das "t = t / 10000" heissen


    Die SID könntest du am RasPi auslesen wenn du die DS18b20 direkt anschließt.
    War mir zuviel Arbeit. Hab die einfach fortlaufend numeriert.

    Quellcode

    1.  --print("temp1/10000:" ..t.. "next")


    ich hab die letzte lua von github, da stehts anderst (https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_modules/ds18b20/ds18b20.lua)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von ganele ()

  • RE: ESP8266 schickt Temperatur an SHC

    Danke nochmals, hat jetzt super geklappt. :D

    Vorher den ds18b20 Sensor mit RPI ausgelesen wegen
    der SID (Code 28).
    Danach die ds18b20.lua von Github geholt,
    und die shc.lua mit einem Sensorpoint
    und der Sensor SID bestückt.
    Und es geht.

    Habe mal am 2. ESP einen ds18s20 (Code 10) installiert,
    wird auch in SHC angezeigt aber die Temperatur
    zeigt nur 3,24 Grad.

    Liegt es an der ds18b20.lua, eine ds18s20 kann ich nicht finden.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von premo ()

  • RE: ESP8266 schickt Temperatur an SHC

    Laut Esplorer Ausgabe von ESP3 sind es nur 3 Grad

    Quellcode

    1. NodeMCU 0.9.6 build 20150216  powered by Lua 5.1.4
    2. 192.168.178.44 255.255.255.0 192.168.178.1
    3. > ESP8266 mode is: 1
    4. The module MAC address is: 1A-FE-34-A1-9B-31
    5. Config done, IP is 192.168.178.44
    6. Temp:3 C
    7. daten an shc gesendet3
    8. Got disconnection...
    9. daten an shc gesendet2.9375
    10. Got disconnection...
    11. PORT CLOSED
    Alles anzeigen


    In SHC sieht es so aus:

    Quellcode

    1. ESP2 22,0 °C
    2. ESP3 2,9 °C
  • RE: ESP8266 schickt Temperatur an SHC

    Die Library funktioniert eigentlich mit allen DS18 Sensoren. Ich passe individuell die Temperaturwerte, die ausgelesen
    werden an. (t=t+(-)x. Außerdem kann man ja auch im SHC den Offset noch einstellen.

    Momentan kämpfe ich mit nem DHT11 am ESP. Er funktioniert, aber die Temperaturwerte sind noch nicht
    sonderlich stabil. (Für einen Heizungssteuerung würde ich immer noch einen DS18x nehmen.)

    Sobald ich mich mit GutHub auskenne, dann stelle ich mal alle meine Libs und Programme da rein.

    Die Codes für die DS18 Sensoren kann man auch selbst erstellen und muss die Originale nicht erst auslesen.
    Sie müssen lediglich einem DS18c Code (Adresse) ähneln. Das SHC schluckt das schon.....
    Man muss nur darauf achten, dass jeder eindeutig ist.
    Lebe deine Träume als ein Leben lang nur zu träumen!

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von hthuering ()

  • RE: ESP8266 schickt Temperatur an SHC

    Hallo

    Ich versuche gerade ein DHT22 zum laufen zubekommen.
    Leider ohne Erfolg.
    Benötige ich auch wie bei DS18 eine init.lua.
    Meine .lua die ich benutze sehen so aus.

    dht22.lua:

    Quellcode

    1. -- ***************************************************************************
    2. -- DHT22 module for ESP8266 with nodeMCU
    3. --
    4. -- Written by Javier Yanez
    5. -- but based on a script of Pigs Fly from ESP8266.com forum
    6. --
    7. -- MIT license, http://opensource.org/licenses/MIT
    8. -- ***************************************************************************
    9. local moduleName = ...
    10. local M = {}
    11. _G[moduleName] = M
    12. local humidity
    13. local temperature
    14. function M.read(pin)
    15.  local checksum
    16.  local checksumTest
    17.  humidity = 0
    18.  temperature = 0
    19.  checksum = 0
    20.  -- Use Markus Gritsch trick to speed up read/write on GPIO
    21.  local gpio_read = gpio.read
    22.  
    23.  local bitStream = {}
    24.  for j = 1, 40, 1 do
    25.    bitStream[j] = 0
    26.  end
    27.  local bitlength = 0
    28.  -- Step 1:  send out start signal to DHT22
    29.  gpio.mode(pin, gpio.OUTPUT)
    30.  gpio.write(pin, gpio.HIGH)
    31.  tmr.delay(150)
    32.  gpio.write(pin, gpio.LOW)
    33.  --tmr.delay(20000)
    34.  tmr.delay(40)
    35.  --delayMicroseconds(40)
    36.  --gpio.write(pin, gpio.HIGH)
    37.  gpio.mode(pin, gpio.INPUT)
    38.  -- Step 2:  DHT22 send response signal
    39.  -- bus will always let up eventually, don't bother with timeout
    40.  while (gpio_read(pin) == 0 ) do end
    41.  local c=0
    42.  while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
    43.  -- bus will always let up eventually, don't bother with timeout
    44.  while (gpio_read(pin) == 0 ) do end
    45.  c=0
    46.  while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
    47.  
    48.  -- Step 3: DHT22 send data
    49.  for j = 1, 40, 1 do
    50.    while (gpio_read(pin) == 1 and bitlength < 10 ) do
    51.      bitlength = bitlength + 1
    52.    end
    53.    bitStream[j] = bitlength
    54.    bitlength = 0
    55.    -- bus will always let up eventually, don't bother with timeout
    56.    while (gpio_read(pin) == 0) do end
    57.  end
    58.  --DHT data acquired, process.
    59.  for i = 1, 16, 1 do
    60.    if (bitStream[i] > 4) then
    61.      humidity = humidity + 2 ^ (16 - i)
    62.    end
    63.  end
    64.  for i = 1, 16, 1 do
    65.    if (bitStream[i + 16] > 4) then
    66.      temperature = temperature + 2 ^ (16 - i)
    67.    end
    68.  end
    69.  for i = 1, 8, 1 do
    70.    if (bitStream[i + 32] > 4) then
    71.      checksum = checksum + 2 ^ (8 - i)
    72.    end
    73.  end
    74.  checksumTest = (bit.band(humidity, 0xFF) + bit.rshift(humidity, 8) + bit.band(temperature, 0xFF) + bit.rshift(temperature, 8))
    75.  checksumTest = bit.band(checksumTest, 0xFF)
    76.  if temperature > 0x8000 then
    77.    -- convert to negative format
    78.    temperature = -(temperature - 0x8000)
    79.  end
    80.  -- conditions compatible con float point and integer
    81.  if (checksumTest - checksum >= 1) or (checksum - checksumTest >= 1) then
    82.    humidity = nil
    83.  end
    84.  --Per DHT Arduino Lib
    85.  gpio.mode(pin, gpio.OUTPUT)
    86.  gpio.write(pin, gpio.HIGH)
    87. end
    88. function M.getTemperature()
    89.  return temperature
    90. end
    91. function M.getHumidity()
    92.  return humidity
    93. end
    94. return M
    Alles anzeigen


    shcdht22.lua:

    Brainfuck-Quellcode

    1. --------------------------------------
    2. -- DS18B20 Temperatur Webserver mit statischer IP und Auto-Refresh
    3. --------------------------------------
    4. -- Quellen
    5. --   github.com/nodemcu/nodemcu-firmware#connect-to-your-ap
    6. --   github.com/nodemcu/nodemcu-firmware#or-a-simple-http-server
    7. --   github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/ds18b20
    8. --------------------------------------
    9. print("DHT22 v.0.1")
    10. function read_temp()
    11. PIN = 4 --  data pin, GPIO0
    12. dht22 = require("dht22")
    13. dht22.read(PIN)
    14. t = dht22.getTemperature()
    15. h = dht22.getHumidity()
    16. if h == nil then
    17. print("Error reading from DHT22")
    18. else
    19. t1 = string.sub(t,1,2)
    20. t2 = string.sub(t,3,4)
    21. h1 = string.sub(h,1,2)
    22. h2 = string.sub(h,3,4)
    23. if t2 == nil then
    24. t2 = 0
    25. elseif h2 == nil then
    26. h2 = 0
    27. end
    28. print ("t:" ..t1.. "." .. t2.. "\nh:" ..h1.. "." ..h2.. "\n")
    29. return t1,t2,h1,h2
    30. end
    31. -- release module
    32. dht22 = nil
    33. package.loaded["dht22"]=nil
    34. end
    35. ---------------------------------------
    36. function send_to_shc()
    37. print("Sending data to shc 2.2 ...")
    38. read_temp()
    39. --print("temp:" ..temperatur.. "\n")
    40. conn=net.createConnection(net.TCP, 0)
    41. conn:on("receive", function(conn, payload) print(payload) end)
    42. -- senden an shc
    43. conn:connect(80,"192.168.178.38") <- shc ip
    44. conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=3&sid=1&type=2&v1=" ..t1.. "." ..t2.. "&v2=" ..h1.. "." ..h2.. " HTTP/1.1\r\n") <- id anpassen
    45. conn:send("Host: 192.168.178.38\r\n")  <-shc ip
    46. conn:send("Accept: */*\r\n")
    47. conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
    48. conn:send("\r\n")
    49. conn:on("sent",function(conn)
    50.                     --print("Closing connection")
    51.                     conn:close()
    52.                     print("daten an shc gesendet\n" ..t1.. "." ..t2.. "\nh:" ..h1.. "." ..h2.. "\n")
    53.                 end)
    54. conn:on("disconnection", function(conn)
    55.                               print("Got disconnection...")
    56. end)
    57. end
    58. -----------------------------------------------
    59. -- STA Modus
    60. wifi.setmode(wifi.STATION)
    61. -- SSID, Passwort
    62. wifi.sta.config("FritzRepeater2", "93728348") <-- wlan einstellungen
    63. ---------------------------------
    64. -- Statische IP
    65. wifi.sta.setip({ip="192.168.178.45",netmask="255.255.255.0",gateway="192.168.178.1"}) <-- daten für feste ip
    66. print(wifi.sta.getip())
    67. read_temp()
    68. send_to_shc()
    69. --- alle 30sek an shc senden
    70. tmr.alarm(0, 30000, 1, function()
    71. send_to_shc()
    72. end)
    Alles anzeigen
  • RE: ESP8266 schickt Temperatur an SHC

    premo schrieb:


    Hallo

    Ich versuche gerade ein DHT22 zum laufen zubekommen.
    Leider ohne Erfolg.
    Benötige ich auch wie bei DS18 eine init.lua.
    Meine .lua die ich benutze sehen so aus.


    Hallo, habe mir deine .lua jetzt nicht angeschaut, aber eine init.lua wird immer benötigt.
    Ob du hier sämtliche Funktionen einbaust oder nur als kurze Startsequenz nutzt und die anderen
    Funktionen über eigene .lua nutzt ist egal.
    Ohne Init.lua läuft nix.