Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How to use LoPy NanoGateway and local MQTT Broker Mosquitto

    Scheduled Pinned Locked Moved LoPy
    lopymqttmosquittonanogateway
    5 Posts 2 Posters 3.3k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ledbelly2142L Offline
      ledbelly2142
      last edited by

      I am new to micropython and have been going over the examples of the Nano-Gateway connecting to public MQTT brokers like TTN. I would like to use the LoPy Nano-Gateway to connect LoPy MQTT client nodes through the Nano-Gateway to the local network to a Mosquitto MQTT broker with a static IP address.

      I was looking at the LoRaWAN Nano-Gateway example HERE to modify and point to the local MQTT broker with the static IP address.

      My understanding is that the Nano-Gateway can act as a proxy to connect LoRa nodes (with sensors) to the Nano-Gateway and publish to the MQTT broker on the local network.

      In the example code, the config.py file shows the server address and port to forward received data to. I think this is where I would enter the MQTT static IP address and port number. The LoPy MQTT client nodes would then publish topics. In the example code, I don't know if I need either the OTAA (over the air activation) or ABP (Activation By Personalization) in my case.

      Can I just publish topics to the targeted MQTT broker through the Nano-Gateway?

      I searched the forums to find other examples of using the LoPy Nano-Gateway to communicate with a local MQTT broker via WiFi but did not find any. There was an example using the WiPy, but the example did not directly translate to the LoPy Nano-Gateway.

      Question: is this the best example code to work from or is there something more straight forward?

      Friends don't let friends run with scissors

      1 Reply Last reply Reply Quote 0
      • ahaw021A Offline
        ahaw021
        last edited by

        hi @ledbelly2142

        I would suggest a gentle review of the MQTT protocol

        What you are missing is that there is a broker and a client. The brokers are significantly more complex than just the clients.

        If you have a look at the pycom library and specifically the MQTT library you will see that only a client has been implemented https://github.com/pycom/pycom-libraries/blob/master/lib/mqtt/mqtt.py

        So you will not be able to run a broker unless you include a 3rd party library.

        http://www.hivemq.com/mqtt-essentials/

        Andrei

        1 Reply Last reply Reply Quote 0
        • ledbelly2142L Offline
          ledbelly2142
          last edited by ledbelly2142

          @ahaw021
          Thank you for your response. I agree, I need an MQTT broker. I have installed mosquitto from mosquitto.org
          It has the static IP address I mentioned in my post earlier. I tested MQTT broker with development clients and tools, so I'm pretty sure it works for publishing and subscribing. I was looking at using the MQTT library discussed in the tutorial for the WiPy HERE. It uses the UMQTT library located on HERE I'm confident the micropython would work as an additional to some or all of the node libraries, the ABP (Activation By Personalization) or OTAA (Over The Air Activation) in the Nano-Gateway example HERE .

          I think you are right that the Pycom MQTT library will work better. Using the PyCom MQTT lib as a starting point for for the Nano-Gateway makes more sense.

          I am asking for some guidance on how to mash up these examples to have the LoPy nodes publish through the Nano-Gateway to an existing MQTT broker on a private network.

          Friends don't let friends run with scissors

          ahaw021A 1 Reply Last reply Reply Quote 0
          • ahaw021A Offline
            ahaw021 @ledbelly2142
            last edited by

            @ledbelly2142

            I think we may be going around in circles

            A LoRaWAN server is not an MQTT server

            For example

            LoPy -> LoRaWAN Gateway (maybe a LoPy) - this is OTAA and ABP
            LoRaWAN Gateway via TCP/UDP -> LoRaWAN Server (this is in line with LoRaWAN Protocol)
            LoRaWAN Server -> MQTT/HTTP <- external services

            The things network for example is a distributed LoRaWan Server

            The functionalities of the LoRaWAN server and an mqtt broker are not exchangeable

            You cannot use a LoRaWAN gateway with the MQTT protocol

            Andrei

            1 Reply Last reply Reply Quote 0
            • ledbelly2142L Offline
              ledbelly2142
              last edited by

              Thanks @ahaw021

              I am still wrapping my mind around how to go from sensor/MQTT-->LoPy send via LoRa to a LoPy acting as a RAW LoRa Nano-Gateway/LoPy--> that then forwards the message over wifi on local network.

              LoPy/LoRa Node --> LoPy/LoRa NanoGateway (recieves and forwards via WiFi)-->LoPy/WiFi NanoGateway --> local network.

              I apologize that I have not been very clear in my posts. In the LoPy NanoGateway discussion
              "The nodes send messages to the Nano-Gateway for further processing, this might include sending the messages over WiFi to a server for example."

              I want to forward messages over WiFi. The MQTT example HERE uses WiFi to send client messages to the MQTT Broker.

              Each LoRa/LoPy node needs to send the data to the NanoGateway, the NanoGateway needs to send it to the MQTT Broker.

              I don't know if there is a simple programmatic way to assemble and send the messages/topics from the NanoGateway to the MQTT Broker. Ideally it would just publish topics/data based on the message payload from the LoPy node. However, this hard codes publishing topics in node code.

              In the LoPy RAW NanoGateway example HERE the node code the message payload (Sensor Data Here) could include sensor data that the NanoGateway would publish the topic to the MQTT broker.

                  msg = "Sensor Data Here"
                  pkg = struct.pack(_LORA_PKG_FORMAT % len(msg), DEVICE_ID, len(msg), msg)
                  lora_sock.send(pkg)
              

              It seems like this would work, but I would like the message payload to be inclusive like

                  msg = "client.publish("/sensors/sensor8/print(temp)")"
                  pkg = struct.pack(_LORA_PKG_FORMAT % len(msg), DEVICE_ID, len(msg), msg)
                  lora_sock.send(pkg)
              

              I am not sure of a proper syntax to send in the message payload for parsing and forwarding. Perhaps just the topic e.g. /sensors/sensor8/temp, print(temp)

              The NanoGateway would receive the message payload and publish the topic with something like:

              client.publish("/sensors/sensor8/temp", "72.3")
              

              This would hard code each LoRa/LoPy sensor node with its topics, which is not very flexible. And I think this is just on way, not sure how to forward a node subscribing back via LoRa from the NanoGateway.

              Has anyone done anything like this?

              Any feedback is appreciated.

              Friends don't let friends run with scissors

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom