element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Arduino MKR WAN 1310 integration with The Things Network MQTT
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 13 Jan 2024 6:05 PM Date Created
  • Views 1596 views
  • Likes 8 likes
  • Comments 6 comments
  • mqtt
  • lorawan
  • the_things_network
  • iot
  • arduino
Related
Recommended

Arduino MKR WAN 1310 integration with The Things Network MQTT

Jan Cumps
Jan Cumps
13 Jan 2024
Arduino MKR WAN 1310 integration with The Things Network MQTT

I connected an Arduino MKR WAN 1310 to The Things Network. Then tested if the Arduino uplinks are published on TTN MQTT service. And if I can publish a downlink message on that service too. This post is my log of the activity.

image
image source: me

Read this post first:  Arduino MKR WAN 1310 on The Things Network (TTN) . This posts starts at the point where the Arduino is working with The Things Network (TTN). 

The Example setup

An Arduino MKR WAN 1310 is registered and tested on TTN ( Arduino MKR WAN 1310 on The Things Network (TTN) ). 
TTN MQTT service integration is enabled.
Data that the Arduino uplinks via LoRaWan, arrives on a TTN MQTT topic.
Data that's published to a topic on that TTN MQTT service, arrives on the Arduino as a downlink.

image

Earlier, I showed how to integrate with the AWS IoT MQTT service. That allows you to use your data with all AWS services.
This is simpler. It's a direct integration within the TTN network. You can use an MQTT client (or Node-RED, ...) to exchange messages.

Assumptions:

  • you have your Arduino MKR WAN 1310 integrated with TTN
  • you have (or download an MQTT client. I use MQTTX. It has to support MQTT 3.1.1.

Steps:

  • enable integration of your TTN application with the MQTT service
  • configure an MQTT client
  • test uplink to MQTT and
  • test downlink from MQTT

We don't have to change the Arduino code or modify existing TTN setup. The integration is (same as with AWS before) an extension, not a modification.

Enable TTN to MQTT integration

Enable the integration and set up a password

The integration is actually enabled by default. You just need to get an access key for your client. From the TTN console, open your application, and navigate to Integrations -> MQTT.  The console shows all settings you need, except for the password. Generate that.

image

Take care to copy the key and store it in a safe place. It 'll be your MQTT password.

Test the integration with TTN MQTT

TTN has written a good manual for that too: TTN MQTT Server. I followed the exact steps and it worked. I downloaded MQTTX as test client. In a real application, you could use Node-RED flows...

Take over the settings from your console. The password is the one you saved a few steps ago when generating the new API key. Set the MQTT version to 3.1.1. Else the client connection will fail.

image

Connect.

uplink from Arduino

To see incoming messages, Subscribe to topic v3/*****-01@ttn/devices/****7/up. (pattern: v3/{application id}/devices/{device id}/up).As soon as your Arduino sends a message over LoRaWan, it will appear in MQTT log . Here's a capture of an incoming payload:

image

That works. The payload is JSON, because we provided an uplink formatter in our TTN device setup.

downlink to Arduino

We can test that with MQTTX too. Publish a message to the v3/********-01@ttn/devices/*************7/down/push topic. (pattern: v3/{application id}/devices/{device id}/down/push)

Payload:

{
  "downlinks": [{
    "f_port": 1,
    "decoded_payload": {
      "ledState": "on"
    },
    "priority": "NORMAL"
  }]
}

We can also use JSON here, because we have a downlink formatter in TTN.

The message will immediately appear in the live data log in the TTN console

image

But will not yet arrive on the Arduino. That's because we'll only get downlink data when we start a communication (design choice in my sketch). Once we receive an uplink from the Arduino, the downlink is sent back:

image

And the LED will light up Slight smile

image

One more exercise:  Arduino MKR WAN 1310 integration with Node-RED via The Things Network .

Enjoy.

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to Jan Cumps

    A little more elaborate. Get the payload as a text and a bool, on the dashboard:

    image

    Flow:

    image

    top flow controls the button, middle one the text box of the dashboard
    lowest flow is a test to see if I can change the JSON type from a string ("on|off") to a bool (true|false) in place. yes.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to Jan Cumps

    uplink data on the Node-RED dashboard:

    image

    I could turn this into an indicator, but the goal was to show that this is an end-to-end integration

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Integration with Node-RED works:

    image

    The example above shows an LoRaWan uplink from the Arduino.

    • received by a gateway in the neighbourhood (mine Slight smile)
    • forwarded to TTN
    • within TTN, integrated with their MQTT service
    • on a Node-RED device here, I subscribed to uplink messages
    • the Node-RED debug node dumps the full payload (I used the JSON formatter, could have use a JSON query to only get my ledState)

    And a downlink example:

    image

    TTN received the Node-RED message

    image

    ... and at the next uplink, the Arduino received it too, and switched its LED on.

    image

    hopla:

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 1 year ago

    Nice post Jan.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 1 year ago

    Very useful info. And the great thing is that everything is standards-based, no inventing of protocols to implement a very useful IoT solution : ) And the solution is entirely compatible with off-the-shelf LoRaWAN sensors/actuators too.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube