The use of the ESP8266 in the world of IoT

User avatar
By dacb
#19301 http://flows.nodered.org/flow/a84e52d28eaf2dea03e6

The frankenstein firmware has a ton of support for common hardware configurations from direct manipulation of the I/O pins, to i2c (and i2c expanders), temperature sensors like the ds18b20 used in this example and other misc features. Plus, it does OTA flashing if you need it.

This Node-red prototype flow shows how to use the frankenstein firmware to generate MTQQ messages, thingspeak updates, etc.

Hopefully this shows that you can avoid writing any new firmware for the ESP8266 and utilize some of the great stuff already in the commons thereby way lowering the barrier to entry. Flow screenshot attached.

flow.png


Running on TheThingbox.
You do not have the required permissions to view the files attached to this post.
User avatar
By cal
#19314 Moin,

cool stuff.
Where does the flow actually run?
If that some controller outside the frankenstein esp that issues commands to the esp or does it run on the esp?

Would it make sense to translate the generated flow to some lua code that runs on the nodemcu firmware
without external coordination?

So many things so little time.

Cal
User avatar
By Artem Pastukhov
#19315 Great!
But i prefer to use nodemcu with mqtt.
My lua code:
Code: Select alltmr.alarm(2, 10000, 1, function ()
      local t,h =dofile("yet-another-dht22.lc").read(2,true)
      if t  and h then
        print("Temperature: "..((t-(t % 10)) / 10).."."..(t % 10).." deg C")
        print("Humidity: "..((h - (h % 10)) / 10).."."..(h % 10).."%")
        print("Sendind temperature and humidity")
        m:publish("events/esp8266/".. chipid .."/temperature",
        cjson.encode({Type = "Temperature", SensorID = chipid, Temperature = ((t-(t % 10)) / 10).."."..(t % 10)})  ,0,0)
        m:publish("events/esp8266/".. chipid .."/humidity",
        cjson.encode({Type = "Humidity", SensorID = chipid, Humidity = ((h - (h % 10)) / 10).."."..(h % 10)})  ,0,0)
      end

end)

And node-red flow:
Code: Select all[{"id":"95df45c7.e7c0b8","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"41b9d518.57c974","type":"mongodb","hostname":"127.0.0.1","port":"27017","db":"esp8266","name":"esp8266"},{"id":"2e32745c.3519ec","type":"mongodb out","mongodb":"41b9d518.57c974","name":"","collection":"humidity","payonly":true,"upsert":false,"multi":false,"operation":"store","x":521,"y":183,"z":"72eac99f.7e1e3","wires":[]},{"id":"84b0d199.1b7a7","type":"mqtt in","name":"","topic":"events/esp8266/10641502/humidity","broker":"95df45c7.e7c0b8","x":178,"y":182,"z":"72eac99f.7e1e3","wires":[["2e32745c.3519ec"]]}]
User avatar
By cal
#19324 Not fair.

You should at least format the js.
Code: Select all[{
    "id": "95df45c7.e7c0b8",
    "type": "mqtt-broker",
    "broker": "localhost",
    "port": "1883",
    "clientid": ""
}, {
    "id": "41b9d518.57c974",
    "type": "mongodb",
    "hostname": "127.0.0.1",
    "port": "27017",
    "db": "esp8266",
    "name": "esp8266"
}, {
    "id": "2e32745c.3519ec",
    "type": "mongodb out",
    "mongodb": "41b9d518.57c974",
    "name": "",
    "collection": "humidity",
    "payonly": true,
    "upsert": false,
    "multi": false,
    "operation": "store",
    "x": 521,
    "y": 183,
    "z": "72eac99f.7e1e3",
    "wires": []
}, {
    "id": "84b0d199.1b7a7",
    "type": "mqtt in",
    "name": "",
    "topic": "events/esp8266/10641502/humidity",
    "broker": "95df45c7.e7c0b8",
    "x": 178,
    "y": 182,
    "z": "72eac99f.7e1e3",
    "wires": [
        ["2e32745c.3519ec"]
    ]
}]


Now you anybody can guess with some confidence what that means.
It's reduced to an informational model which has an easy graphical form that allows to see flows.
I can explain that to my mother.
For the lua code you need some more knowledge.
Concepts like callbacks, lambdas, positional parameters that have meaning depending on the position,
syntax, indentation that does not reflect the structure of the code, mental model needed to interpret code
for yourself.

I know both.
If it lowers entry level for starters by using a graphical flow editor thats nice.
You are not programming json or timers or mqtt yourself.
You are using lua as the glue language combining lower level blocks.
Thats IMHO the best usage of such a language. But you need programming skills on text level.
Graphical flow language have a lower entry level and if both are combined that makes a good pair.

Even your example uses json to exchange data. It's just an notation form. It's the model and the model definition
that make up the important part.

Cal