element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Low Power IoT Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Low Power IoT Design Challenge
  • More
  • Cancel
Low Power IoT Design Challenge
Blog Low Power IoT Design Challenge - MQTT Implementation
  • Blog
  • Forum
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 22 Sep 2021 3:53 AM Date Created
  • Views 241 views
  • Likes 1 like
  • Comments 4 comments
  • node red
  • mqtt
  • low_power_iot
  • anycloud_mqtt_client
  • cy8ckit-psoc62s2-43012
  • cypress modus toolbox 2.3
Related
Recommended

Low Power IoT Design Challenge - MQTT Implementation

ralphjy
ralphjy
22 Sep 2021

I plan to use MQTT messages to communicate between the PSoC 62S2 and a local MQTT broker that I have running on an RPi4.

 

The PSoC 62S2 will subscribe to detection messages from the remote microwave sensor and publish classification and recognition messages.

 

The first thing that I need to verify is that I can send and receive messages (publish and subscribe to topics) to/from the broker.

 

Modus Toolbox includes an example to do that using an AWS broker - AnyCloud_MQTT_Client.  I am running on my LAN with a private broker, so I need to make some minor tweaks to their example.

 

 

I just need to modify 2 configuration files:

     wifi_config.h to add my wifi network name and password

     mqtt_client_config.h to add the broker ip address and port and any TLS information

 

 

I thought this would be very easy because I don't run TLS when operating within my private LAN, so I wasn't going use TLS and didn't need to generate any certificates (I'll probably switch to that at some point).  So, basically all I needed to do was indicate that I'm not using TLS and also switch the port number from (8883 to 1883).

 

There are 2 lines in the mqtt_client_config.h file:

     #define MQTT_SECURE_CONNECTION            ( 0 )   // change from 1 to 0

     #define MQTT_PORT                         1883                   // change from 8883 to 1883 -> 8883 is the default TLS port

 

Of course, nothing is that easy.  Just simply changing the MQTT_SECURE_CONNECTION to "0" would cause the build to fail (I had verified it would build with "1").

 

Here is the build error message:

     source/mqtt_client_config.c:118:38: error: conflicting types for 'security_info'

       118 | struct cy_awsport_ssl_credentials_t *security_info = NULL;

 

     In file included from source/mqtt_client_config.c:44:

     ./configs/mqtt_client_config.h:192:39: note: previous declaration of 'security_info' was here

       192 | extern cy_awsport_ssl_credentials_t  *security_info;

 

I needed to delete the "struct" declaration so that line 118 in mqtt_client_config.c became

     118 | cy_awsport_ssl_credentials_t *security_info = NULL;

 

That fixed the build error.

 

Application demo

 

In this particular application, the PSoC 62S2 both publishes and subscribes to the topic "ledstatus" which creates a message loopback.  When the user button (SW2) is pressed the published message alternates between "TURN ON" or "TURN OFF" to the topic "ledstatus".

 

Since the board is also subscribed to the "ledstatus" topic, it responds to the message by turning the user LED on or off.

 

Here is the USB serial output in a PuTTY terminal window.

 

And a short video showing the interaction.

 

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

 

 

My next steps are to add the microwave sensor and the capability to display received messages on the E-Paper Display (EPD).

Anonymous
Parents
  • Jan Cumps
    Jan Cumps 8 months ago

    Ralph, have you considered to enable security on the MQTT server instead of disabling it on the client?

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • ralphjy
    ralphjy 8 months ago in reply to Jan Cumps

    Hi Jan,

     

    When operating on my local LAN, I tend not to enable security for MQTT so that I don't have to generate certificates for each device that I add.  Just laziness I guess.  I should be more disciplined.

     

    Ralph

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps 8 months ago in reply to ralphjy

    I blame the early MQTT tutorials, that learned the developers how to turn off security instead of how to embrace it.

    The ModusToolbox AnyCloud examples are good exceptions. They  show how a client application can do safe IoT.

     

    (fun fact: I turned the light on in ipv1's baby bedroom, and took over one of the Hackaday finalists' designs in a contest)

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Comment
  • Jan Cumps
    Jan Cumps 8 months ago in reply to ralphjy

    I blame the early MQTT tutorials, that learned the developers how to turn off security instead of how to embrace it.

    The ModusToolbox AnyCloud examples are good exceptions. They  show how a client application can do safe IoT.

     

    (fun fact: I turned the light on in ipv1's baby bedroom, and took over one of the Hackaday finalists' designs in a contest)

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Children
  • ralphjy
    ralphjy 8 months ago in reply to Jan Cumps

    I'll have to remember that when I see strange things going on ....

     

    More seriously, I agree with your comment about security.  I'm glad to see the Trust hardware being deployed for IoT devices.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube