Hello, I'm trying to use python function which will be triggered each x minutes ... (mainly because of learning experience, as I have it crontabed anyways)
I'm using node-red-contrib-python-function but I'm having difficulties to understand how python node passing data
It seems it's passing them, but not in msg.payload as it looks from this flow and debug
I have two debugs, one for payload and one for whole object.
In object there is a number
In msg.payload there is nothing, and mqtt node complains about something strange.
Any hint would be really appreciated.
(as for test, there are two outputs just for convenient testing, this function reads luminosity sensor and resulting in number)
flow
[{"id":"1bdd464f.bab3fa","type":"python-function","z":"941ada45.f00b08","name":"luminosity","func":"import smbus\nimport time\n\n# Get I2C bus\nbus = smbus.SMBus(1)\n\nbus.write_byte_data(0x39, 0x00 | 0x80, 0x03)\nbus.write_byte_data(0x39, 0x01 | 0x80, 0x02)\n\ntime.sleep(0.5)\ndata = bus.read_i2c_block_data(0x39, 0x0C | 0x80, 2)\ndata1 = bus.read_i2c_block_data(0x39, 0x0E | 0x80, 2)\n\n# Convert the data\nch0 = data[1] * 256 + data[0]\nch1 = data1[1] * 256 + data1[0]\n\nmsg = ch0-ch1\n\ntest = 23\n\nreturn [ msg, test ]","outputs":2,"x":420,"y":120,"wires":[["68e6ee9c.2dc9e","67728ffb.a4ff6"],["f9ccf07f.3b6e6"]]},{"id":"68e6ee9c.2dc9e","type":"debug","z":"941ada45.f00b08","name":"payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":680,"y":180,"wires":[]},{"id":"ebd80287.b79b9","type":"inject","z":"941ada45.f00b08","name":"3 min","topic":"","payload":"true","payloadType":"bool","repeat":"180","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":120,"wires":[["1bdd464f.bab3fa"]]},{"id":"67728ffb.a4ff6","type":"mqtt out","z":"941ada45.f00b08","name":"luminosity","topic":"homew/weather/light","qos":"0","retain":"false","broker":"df8d19b3.781d88","x":700,"y":100,"wires":[]},{"id":"f9ccf07f.3b6e6","type":"debug","z":"941ada45.f00b08","name":"msg object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":220,"wires":[]},{"id":"df8d19b3.781d88","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.0.25","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
debug:
2/3/2020, 4:15:12 PM
node: payload
msg.payload : undefined
undefined
2/3/2020, 4:15:12 PM
node: luminosity
msg : error
"TypeError: Cannot create property 'qos' on number '43'"
2/3/2020, 4:15:12 PM
node: msg object
msg : number
23