element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Secure MQTT integration between Node-RED and The Things Network
  • 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: 26 Jan 2024 11:17 AM Date Created
  • Views 1910 views
  • Likes 9 likes
  • Comments 3 comments
  • mqtt
  • the things network
  • internet_of_things
  • node-red
  • ttn
  • the_things_network
  • iot
  • tls
  • mqtts
Related
Recommended

Secure MQTT integration between Node-RED and The Things Network

Jan Cumps
Jan Cumps
26 Jan 2024

I connected an Arduino MKR WAN 1310 to The Things Network (TTN). Then used Node-RED to connect to the TTN MQTT service and work with the data. Now I'm enabling safe TLS communication to the MQTT. This post is my log of the activity.

image
image source: me

Read this post first:  Arduino MKR WAN 1310 integration with Node-RED via The Things Network  This posts starts at the point where Node-RED is working with plain TTN MQTT. 

What? Why TLS?

MQTT is secured by user name and password. When you use the standard MQTT protocol, this info - and the payload you exchange - is readable by bad human beings. MQTTS solves this, by allowing verified and encrypted data exchange.

  • verify: server is who we think it is
  • encrypt: data runs over TLS

This is an uneventful post. In the previous one, we were able to connect to TTN MQTT. In this post, we will be able to do the same. But safer.

What's required?

We need a downloadable certificate:

  • the ROOT Trust certificate of letsencrypt.org (valid until 2035). Or a TTN MQTT server certificate (usually valid for a few months)
  • (ideally also a client cert and private key, but I haven't found out yet how to generate or get one for this chain.)

TTN uses Let's Encrypt as authority. We can let Node-RED validate the server by giving it their trust certificate. Here is where you can retrieve it: https://letsencrypt.org/certs/isrgrootx1.pem. Save it.

For tighter validation, the TTN server certificate can be retrieved by surfing to your TTN console. In your browser, then click on the security/settings icon (a lock in some browser). In chrome, it looks like this:
image

Save as Base64 CER, next to the first one you downloaded.
Alternatively you can use a Node-RED flow to retrieve that certificate.

Tomato Tomato? The TTN provided certificate will match exactly that server, and for a shorter period. The letsencypt one will validate that the server has a certificate trusted by them...

Configure Node-RED MQTT connection for TLS

You have two MQTT connections on your Node-RED flow (if you followed  Arduino MKR WAN 1310 integration with Node-RED via The Things Network ). We 'll change one to MQTTS. In the second one, we can then select that new setup.

Open the uplink connection:

image

In the Server setting, select Add new mqtt-broker, and name it ttnmqtts. Connection and Security tab settings are mostly the same as in the original config. Take them over.

Then make these changes:

image

Port: 8883

Check Use TLS, and Add new tls-config

In that config, upload the two certificates:

image

Confirm everything. Before deploying the flow, open a console to your Node-RED server and start the Node-RED log

node-red-log

Deploy the changes in Node-RED, and check the log:

image

If all is OK, you should see that one MQTTS/TLS connection is made to port 8883 (the new config we did for the uplink node. And the old node still uses plain MQTT over 1883.

All you have to do now, is select that new ttnmqtts serve configuration in the downlink node, and deploy again.

image

The log file now only shows one connection, to the 8883 port. Success.

You can now delete the old ttnmqtt server configuration and never look back.

image

  • Sign in to reply
Parents
  • DAB
    DAB over 1 year ago

    Nice update Jan.

    I like the secure option, this would be very useful for important data transfer.

    It would also make spoofing more difficult.

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

    In particular the password. The rest of the data is less sensitive.

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

    In particular the password. The rest of the data is less sensitive.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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