Raspberry PI + MQTT (Mosquitto) + Serial Gateway



  • Hi,

    I'm looking for combination of those 3 things from topic.

    I going to use RaspberryPi as a gateway, MQTT broker and controller in one device.

    I need MQTT (in future I going to use WiFi sensors too), but MQTT gateway from MySensors on Arduino is not enough for me because it allows only for one connections and has too simple logic regarding subscripitions.

    I was going to use SerialGateway (or direct nRF24L01 connection to RPi) because I want to connect whole controller/gateway stuff to UPS - if I have Ethernet or MQTT gateway separately to RPi then I need to connect RPI, Ethernet/MQTT gateway and router to UPS, but I have it in diferent localizations.

    I've fount that there is RPi port of MySensors lib: https://github.com/mysensors/Raspberry, but without MQTT support.

    I've also found bridge between Arduino ethernet gateway and MQTT broker with Perl script: https://github.com/mysensors/PerlMQTTGateway

    ... but cannot find compilation of those 3 things together. Maybe I missed someting and maybe there is reason for that is not connected together. I've gone through this forum but without success.

    Maybe you can give me some hints how to deal with it?

    Thanks.
    Regards,
    Michal


  • Hardware Contributor

    I am using https://github.com/Yveaux/MySensors_MQTTGateway
    with serial gateway



  • @Mrlynx Did you make some changes or it works in this way out of the box?



  • Oh, I think I have it, you mean mqttGateway2.pl works with serial gateway. mqttGateway2.pl is a little bit different from https://github.com/mysensors/PerlMQTTGateway then from https://github.com/Yveaux/MySensors_MQTTGateway. Anyway thanks I'll check this.


  • Hardware Contributor

    Yes you found the right script.
    I have made some minor changes to use json.



  • What changes did you make for Json support??

    Thanks


  • Hardware Contributor

    @lafleur
    I only changed sub publish to post both timestamp and message in a json message.

    $message = "{\"timestamp\":\"".gettime()."\",\"message\":\"$message\"}"  ;


  • I am trying to get the Perl serial gateway code running on a PI-2, but it looks like it wants a number of .PM file that are missing... I'm not well-versed in Linux, so I need a bit of help...

    Anyone know of a complete package for this project??

    Missing so far:

    AnyEvent/Socket.pm
    Net/MQTT/Constants.pm

    It also complains about: use strict; in the program

    Bareword "MQTT_QOS_AT_MOST_ONCE" not allowed while "strict subs" in use at /etc/perl/Net/MQTT/Constants.pm line 74.
    Compilation failed in require at MQTT_Gateway.pl line 32.
    BEGIN failed--compilation aborted at MQTT_Gateway.pl line 32.

    Thanks


  • Hardware Contributor

    @lafleur
    you have to install all dependensis with cpan

    http://www.cpan.org/modules/INSTALL.html



  • Yes, I did ... heres the last set of error messages...

    perl MQTT_Gateway.pl
    Couldn't require Net::MQTT::Message::ConnAck : Bareword "MQTT_CONNECT_ACCEPTED" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/ConnAck.pm line 19.
    Compilation failed in require at (eval 21) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::Subscribe : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/Subscribe.pm line 16.
    Compilation failed in require at (eval 24) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::Unsubscribe : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/Unsubscribe.pm line 16.
    Compilation failed in require at (eval 25) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::PubRel : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/PubRel.pm line 16.
    Compilation failed in require at (eval 27) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Subroutine main::inet_aton redefined at /usr/share/perl/5.14/Exporter.pm line 67.
     at MQTT_Gateway.pl line 34
    Subroutine new redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 25.
    Subroutine new_from_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 33.
    Subroutine _parse_remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 58.
    Subroutine message_type redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 62.
    Subroutine dup redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 65.
    Subroutine qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 68.
    Subroutine _default_qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 73.
    Subroutine retain redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 78.
    Subroutine remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 81.
    Subroutine _remaining_string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 83.
    Subroutine _remaining_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 88.
    Subroutine string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 91.
    Subroutine bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 106.
    Bareword "MQTT_QOS_AT_MOST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 74.
    Compilation failed in require at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    BEGIN failed--compilation aborted at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    Compilation failed in require at MQTT_Gateway.pl line 36.
    BEGIN failed--compilation aborted at MQTT_Gateway.pl line 36.
    


  • I'm still having issue with running this on a PI2..

    Anyone have it running that could give me some guidance?? I'm not much of a linux guy...

    Thanks

    Insert /usr/bin/perl  -w MQTT_Gateway.pl
    Couldn't require Net::MQTT::Message::ConnAck : Bareword "MQTT_CONNECT_ACCEPTED" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/ConnAck.pm line 19.
    Compilation failed in require at (eval 21) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::Subscribe : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/Subscribe.pm line 16.
    Compilation failed in require at (eval 24) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::Unsubscribe : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/Unsubscribe.pm line 16.
    Compilation failed in require at (eval 25) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Couldn't require Net::MQTT::Message::PubRel : Bareword "MQTT_QOS_AT_LEAST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message/PubRel.pm line 16.
    Compilation failed in require at (eval 27) line 2.
     at /usr/share/perl/5.14/Module/Pluggable.pm line 28
    Subroutine main::inet_aton redefined at /usr/share/perl/5.14/Exporter.pm line 67.
     at MQTT_Gateway.pl line 34
    Subroutine new redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 25.
    Subroutine new_from_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 33.
    Subroutine _parse_remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 58.
    Subroutine message_type redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 62.
    Subroutine dup redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 65.
    Subroutine qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 68.
    Subroutine _default_qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 73.
    Subroutine retain redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 78.
    Subroutine remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 81.
    Subroutine _remaining_string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 83.
    Subroutine _remaining_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 88.
    Subroutine string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 91.
    Subroutine bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 106.
    Bareword "MQTT_QOS_AT_MOST_ONCE" not allowed while "strict subs" in use at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 74.
    Compilation failed in require at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    BEGIN failed--compilation aborted at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    Compilation failed in require at MQTT_Gateway.pl line 36.
    BEGIN failed--compilation aborted at MQTT_Gateway.pl line 36.
    Code Here
    


  • I'm still having issue getting this to run on my PI2... I edited the files and fixed the Bareword issues, but now I get this... Not sure what to do from here..

    Thanks

    Insert Code sudo perl -w MQTT_Gateway.pl
    Subroutine main::inet_aton redefined at /usr/share/perl/5.14/Exporter.pm line 67.
     at MQTT_Gateway.pl line 34
    Subroutine new redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 25.
    Subroutine new_from_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 33.
    Subroutine _parse_remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 58.
    Subroutine message_type redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 62.
    Subroutine dup redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 65.
    Subroutine qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 68.
    Subroutine _default_qos redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 73.
    Subroutine retain redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 78.
    Subroutine remaining redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 81.
    Subroutine _remaining_string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 83.
    Subroutine _remaining_bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 88.
    Subroutine string redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 91.
    Subroutine bytes redefined at /usr/local/share/perl/5.14.2/Net/MQTT/Message.pm line 106.
    Duplicate message_type number 2:
      Net::MQTT::Message::ConnAck and
      Net::MQTT::Message::ConnAck
    Compilation failed in require at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    BEGIN failed--compilation aborted at /usr/local/share/perl/5.14.2/AnyEvent/MQTT.pm line 12.
    Compilation failed in require at MQTT_Gateway.pl line 36.
    BEGIN failed--compilation aborted at MQTT_Gateway.pl line 36.Here
    


  • @catcher bit late, but do you have this serial to mqtt bridge working?
    I would like to use RFM69 radio's which I think don't have a direct MySensors MQTT gateway.
    I have the serial gateway working and can see data on a RasPi 3 via serial0.

    Would like to publish to OpenHab2 via MQTT so this bridge would be great if it works.





  • @gvorster It was some time ago but remember that finally was able to use this script: https://github.com/Yveaux/MySensors_MQTTGateway/blob/master/mqttGateway2.pl
    However currently switched to this: https://www.mysensors.org/build/raspberry
    and must say that works fine for me, and without extra Arduino (just RPi3 and nRF24L01+).



  • @catcher Thanks, I tried this Perl script and it is working out of the box with OpenHAB2! And I'm sending with MySensors 2.



Suggested Topics

  • 3
  • 4
  • 11
  • 9
  • 2
  • 8
  • 13

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts