rtrbt Geschrieben January 24, 2019 at 15:22 Share Geschrieben January 24, 2019 at 15:22 Hi, As of today, a beta version of the MQTT bindings 2.0 is available. Please tinker around with them and post any bugs, suggestions and other feedback here. The MQTT bindings are now generated like other programming language bindings. All Bricks and Bricklets are supported. The bindings map directly to the Python bindings, which is why they are not backwards-compatible to the old MQTT proxy. The MQTT proxy is now discontinued. The current version of the bindings is attached to this post, including examples. The bindings depend on Python >= 2.7.9 or >= 3.4 and the Paho library (>= 1.3.1) available here. The documentation can be found here Have a lot of fun! Erik Edit: Version 2.0.1 - Fix handling of JSON errors for Python 2tinkerforge_mqtt_bindings_2_0_1.zip Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben February 26, 2019 at 13:34 Autor Share Geschrieben February 26, 2019 at 13:34 The MQTT bindings have left the beta phase and are now available on the Tinkerforge home page: https://www.tinkerforge.com/de/doc/Downloads.html The bindings now support the --init-file parameter, which allows loading initial configuration from a file. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 4, 2019 at 17:30 Share Geschrieben March 4, 2019 at 17:30 Hello Forum, just unzipped the new zip file, copied it to /usr/local/bin, made it runable via chmod +x. Now, running it: sudo /usr/local/bin/tinkerforge_mqtt Traceback (most recent call last): File "/usr/local/bin/tinkerforge_mqtt", line 6649, in <module> main() File "/usr/local/bin/tinkerforge_mqtt", line 6646, in main bindings.run(initial_config) File "/usr/local/bin/tinkerforge_mqtt", line 5981, in run for topic, payload in initial_config.items(): AttributeError: 'NoneType' object has no attribute 'items' Exception in thread Disconnect-Prober (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner File "/usr/lib/python2.7/threading.py", line 754, in run File "/usr/local/bin/tinkerforge_mqtt", line 1179, in disconnect_probe_loop <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty' resulted in the messsage above. Could anyone give me a hint, how to use this MQTT Binding? What has to be done, for example, to make this Binding to publish the values from the Outdoor Weather Station. From the example file: # Change XYZ to the UID of your Outdoor Weather Bricklet setup: # Enable station data callbacks publish '{"enable_callback": true}' to tinkerforge/request/outdoor_weather_bricklet/XYZ/set_station_callback_configuration # Enable sensor data callbacks publish '{"enable_callback": true}' to tinkerforge/request/outdoor_weather_bricklet/XYZ/set_sensor_callback_configuration # Handle incoming station data callbacks subscribe to tinkerforge/callback/outdoor_weather_bricklet/XYZ/station_data publish '{"register": true}' to tinkerforge/register/outdoor_weather_bricklet/XYZ/station_data # Register station_data callback # Handle incoming sensor data callbacks subscribe to tinkerforge/callback/outdoor_weather_bricklet/XYZ/sensor_data publish '{"register": true}' to tinkerforge/register/outdoor_weather_bricklet/XYZ/sensor_data # Register sensor_data callback I dont know, or i'm blind, how to put the right command. I'm using a MQTT Broker on another machine. To view all the MQTT-chatter i use MQTT.fx and the new MQTT Explorer from https://github.com/thomasnordquist/MQTT-Explorer Thank you! Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 4, 2019 at 19:06 Autor Share Geschrieben March 4, 2019 at 19:06 Hi, This was a problem on my end. Please try the attached version. To connect to a MQTT broker on another machine, you can run the bindings like this: sudo /usr/local/bin/tinkerforge_mqtt --broker-host <IP> MQTT-Explorer seems to subscribe automatically to all topics, so to see the sensor data, you only have to publish the messages listed in the example.tinkerforge_mqtt_bindings_fixed.zip Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 4, 2019 at 21:33 Share Geschrieben March 4, 2019 at 21:33 Hey, installed the new version. Thank you for your answer. But no luck. Perhaps: WARNING:MQTT bindings:Another MQTT bindings instance started on this broker with the same global prefix. This is not recommended as both bindings instances will receive requests and send responses. Idk what other instance is running here. I send the (json formatted) payload from the example file to the broker. I get a reaction like "callback/binding/restart" ... strange ... Perhaps i should remove the broker and install again. Are there any special requirements for the broker? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 5, 2019 at 08:26 Autor Share Geschrieben March 5, 2019 at 08:26 The message published to "callback/bindings/restart" is sent by the bindings to notify other bindings to print the warning you see. As your broker is running on another machine, my first guess is, that there is a timing problem here: Maybe the bindings see their own restart message. But I need to take another look. For now you can ignore the warning if you are sure, there is no other instance running. Your broker seems to run okay, you don't need to reinstall. For testing purposes you can try to enumerate the attached devices: publish {"register": true} to tinkerforge/register/ip_connection/enumerate and then publish an empty message to tinkerforge/request/ip_connection/enumerate You should then see responses for all found devices under the topic tinkerforge/callback/ip_connection/enumerate Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 5, 2019 at 08:58 Share Geschrieben March 5, 2019 at 08:58 The broker is running on the same machine. So no external host ips are needed. Ok, your given way seems to work/there is a reaction: Output from MQTT Explorer: {"connected_uid": "6evjRp", "uid": "Es8", "device_identifier": "outdoor_weather_bricklet", "hardware_version": [1, 0, 0], "enumeration_type": "available", "position": "a", "firmware_version": [2, 0, 2], "_display_name": "Outdoor Weather Bricklet"} Output from Console: while running tinkerforge_mqtt and posting mqtt messages: ERROR:MQTT bindings:253 ('6kL62k', '0', '0', (2, 0, 0), (2, 4, 10), 13, 0) ERROR:MQTT bindings:253 ('eVC', '6kL62k', 'a', (1, 0, 0), (2, 0, 2), 221, 0) ERROR:MQTT bindings:253 ('eny', '6kL62k', 'b', (1, 1, 0), (2, 0, 3), 21, 0) ERROR:MQTT bindings:253 ('eXk', '6kL62k', 'c', (1, 2, 0), (2, 0, 6), 212, 0) ERROR:MQTT bindings:253 ('eE3', '6kL62k', 'd', (1, 1, 0), (2, 0, 2), 27, 0) ERROR:MQTT bindings:253 ('6evjRp', '6kL62k', '1', (2, 0, 0), (2, 4, 10), 13, 0) ERROR:MQTT bindings:253 ('EQL', '6evjRp', 'b', (1, 1, 0), (2, 0, 4), 216, 0) ERROR:MQTT bindings:253 ('yLJ', '6evjRp', 'd', (2, 0, 0), (2, 0, 2), 259, 0) ERROR:MQTT bindings:253 ('Es8', '6evjRp', 'a', (1, 0, 0), (2, 0, 2), 288, 0) ERROR:MQTT bindings:253 ('6kL62k', '0', '0', (2, 0, 0), (2, 4, 10), 13, 0) ERROR:MQTT bindings:253 ('eVC', '6kL62k', 'a', (1, 0, 0), (2, 0, 2), 221, 0) ERROR:MQTT bindings:253 ('eny', '6kL62k', 'b', (1, 1, 0), (2, 0, 3), 21, 0) ERROR:MQTT bindings:253 ('eXk', '6kL62k', 'c', (1, 2, 0), (2, 0, 6), 212, 0) ERROR:MQTT bindings:253 ('eE3', '6kL62k', 'd', (1, 1, 0), (2, 0, 2), 27, 0) ERROR:MQTT bindings:253 ('6evjRp', '6kL62k', '1', (2, 0, 0), (2, 4, 10), 13, 0) ERROR:MQTT bindings:253 ('EQL', '6evjRp', 'b', (1, 1, 0), (2, 0, 4), 216, 0) ERROR:MQTT bindings:253 ('yLJ', '6evjRp', 'd', (2, 0, 0), (2, 0, 2), 259, 0) ERROR:MQTT bindings:253 ('Es8', '6evjRp', 'a', (1, 0, 0), (2, 0, 2), 288, 0) Output from the console ./tinkerforge enumerate uid=6kL62k connected-uid=0 position=0 hardware-version=2,0,0 firmware-version=2,4,10 device-identifier=master-brick enumeration-type=available uid=eVC connected-uid=6kL62k position=a hardware-version=1,0,0 firmware-version=2,0,2 device-identifier=barometer-bricklet enumeration-type=available uid=eny connected-uid=6kL62k position=b hardware-version=1,1,0 firmware-version=2,0,3 device-identifier=ambient-light-bricklet enumeration-type=available uid=eXk connected-uid=6kL62k position=c hardware-version=1,2,0 firmware-version=2,0,6 device-identifier=lcd-20x4-bricklet enumeration-type=available uid=eE3 connected-uid=6kL62k position=d hardware-version=1,1,0 firmware-version=2,0,2 device-identifier=humidity-bricklet enumeration-type=available uid=6evjRp connected-uid=6kL62k position=1 hardware-version=2,0,0 firmware-version=2,4,10 device-identifier=master-brick enumeration-type=available uid=EQL connected-uid=6evjRp position=b hardware-version=1,1,0 firmware-version=2,0,4 device-identifier=temperature-bricklet enumeration-type=available uid=yLJ connected-uid=6evjRp position=d hardware-version=2,0,0 firmware-version=2,0,2 device-identifier=ambient-light-v2-bricklet enumeration-type=available uid=Es8 connected-uid=6evjRp position=a hardware-version=1,0,0 firmware-version=2,0,2 device-identifier=outdoor-weather-bricklet enumeration-type=available Are there any updates needed? The brickdaemon ist the latest ... Any librarys? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 5, 2019 at 09:06 Autor Share Geschrieben March 5, 2019 at 09:06 The error messages are left-over debug code, I've removed them, this change will be in the next "official" version (will be posted in a few hours). The rest looks good to me. Are the callbacks of the outdoor weather station working too? One thing I've noticed in the documentation: The single quotes are only there to mark the payload, so if you use the MQTT-Explorer, you have to omit them. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 5, 2019 at 10:50 Autor Share Geschrieben March 5, 2019 at 10:50 The official version 2.0.3 is now available here. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 5, 2019 at 16:16 Share Geschrieben March 5, 2019 at 16:16 Hello! thank you very much for your guidance. Within MQTT.fx i can reveive messages from both - the station and the sensor. The process for activating and subscribing is quite long ... and does it have te be done after every reboot ... for every sensor? Are you doing this with MQTT.fx (no paste possible, so manual write for each payload ) or are u using mosquitto_pub and sub in the commandline? What is the best way to autostart the tinkerforge_mqtt system after a reboot? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 5, 2019 at 16:26 Autor Share Geschrieben March 5, 2019 at 16:26 The process for activating and subscribing is quite long ... and does it have te be done after every reboot ... for every sensor? You don't have to configure the callbacky by hand. Instead you can use an init file, as described here. What is the best way to autostart the tinkerforge_mqtt system after a reboot? You could write a systemd service file. This is explained here. You should definitely use init-files then, or else you would have to reconfigure everything after a reboot. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 5, 2019 at 20:00 Share Geschrieben March 5, 2019 at 20:00 this is my init file: { "tinkerforge/request/outdoor_weather_bricklet/Es8/set_station_callback_configuration": {"enable_callback": true}, "tinkerforge/register/outdoor_weather_bricklet/Es8/station_data": {"register": true} } and running it this: sudo /usr/local/bin/tinkerforge_mqtt --init-file stationmqttini.txt But under the used topic, there are no incoming messages. Since there is a init file, i tried to switch off the status led. With the request (empty payload) tinkerforge/request/outdoor_weather_bricklet/Es8/get_status_led_config i wanted to examine the payload structure for request/outdoor_weather_bricklet/<UID>/set_status_led_config But i dont get a response message. Any idea? Because this payload could be added to the init file. Could you please look at my init file and tell me what's wrong? :-) What is your setup for autostart after a reboot? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
riro Geschrieben March 5, 2019 at 20:09 Share Geschrieben March 5, 2019 at 20:09 Publishing {"config": 0} to tinkerforge/request/outdoor_weather_bricklet/Es8/set_status_led_config ... works ... and the led is off. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
rtrbt Geschrieben March 6, 2019 at 08:28 Autor Share Geschrieben March 6, 2019 at 08:28 Your init file looks good, I've tested it here and got callback responses. You could run the bindings with the --debug parameter and check if there are the following lines in the output: <DEBUG> MQTT bindings: Calling function set_station_callback_configuration for device Es8 of type outdoor_weather_bricklet. <DEBUG> MQTT bindings: Calling function set_station_callback_configuration for device Es8 of type outdoor_weather_bricklet succedded. <DEBUG> MQTT bindings: Registered callback station_data for device Es8 of type outdoor_weather_bricklet. Will publish messages to tinkerforge/callback/outdoor_weather_bricklet/Es8/station_data. If these are printed, the bindings should publish a message under the callback topic when there is new data (can take about 45 seconds). The get_status_led_config request works here, but maybe there are some hints in your debug output. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
Bottesford Geschrieben March 18, 2019 at 19:48 Share Geschrieben March 18, 2019 at 19:48 Maybe this will help someone - I created a systemd unit file for auto starting my mqtt bindings for all my TF bricks. Create a file: nano /etc/systemd/system/tf_mqtt@.service [unit] Description=Tinkerforge MQTT %i [service] Type=simple StandardOutput=file:/var/log/tinkerforge_mqtt/tf_mqtt_%i.log ExecStart=/usr/bin/python3 /usr/local/bin/tinkerforge_mqtt --ipcon-host %i --broker-username mqtt --broker-password <password> --global-topic-prefix tf_mqtt_%i [install] WantedBy=multi-user.target To start I pass the ip address (I use fixed ips) of my brick into the command: sudo systemctl start tf_mqtt@192.168.2.150 sudo systemctl start tf_mqtt@192.168.2.151 etc. Then to start on boot: sudo systemctl enable tf_mqtt@192.168.2.150 Now I get all my sensor data under a topic: tf_mqtt_192.168.2.150/# I register my callbacks via a python app in AppDaemon within Home Assistant. This means I can keep all my sensor config (led status, multi touch sensitivity, etc.) together instead of in the init file. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.