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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
1 Meter of Pi
  • Challenges & Projects
  • Design Challenges
  • 1 Meter of Pi
  • More
  • Cancel
1 Meter of Pi
Blog Blog-3 Interfacing more sensors over MQTT
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: embeddedguy
  • Date Created: 14 Dec 2020 2:04 PM Date Created
  • Views 945 views
  • Likes 5 likes
  • Comments 3 comments
  • raspberrypi.org
  • embedded project
Related
Recommended

Blog-3 Interfacing more sensors over MQTT

embeddedguy
embeddedguy
14 Dec 2020

In my last blog, I explained the working of both the Hats connected with pi using the Pico Hat Hacker. There is only one BME temperature/Humidity sensor is connected with this kind of connection.

My idea was to have more sensors at different places of the 1m3 space to monitor the environment effectively. In fact the research shows that the Plant growing chamber currently on IIS in space

has more than 180 different types of sensors to monitor the environment effectively also with IR camera to have control even during the nights. It is not required from the astronauts to take care of \

the chamber every day, more or less it is fully controlled from the ground station.

 

imageimage

imageimage

 

For MQTT with Python, there is Paho.MQTT python package which will be able to receive the sensor data in different ways.

The library has explained callback functions that take care of publishing/subscribing of the sensor values.

In my case, I use the loop functions to publish/subscribe for some time to get the sensor values.

I would collect the sensor values and make the adjustment of light and temperature in a controlled manner.!!

What do you think about my idea?

pip install paho-mqtt

The following code will run inside the main loop to get the remote temperature/humidity data over MQTT.

 

def get_remote_temp():
    client = mqtt.Client()
    client.username_pw_set(mqtt_user, mqtt_pass)
    client.on_connect = on_connect
    client.on_message = on_message
    client.on_disconnect = on_disconnect
    client.loop_start()
    client.connect(ser_add, 1883)
    sleep(3)
    client.loop_stop()

 

There are the following loopback functions

 

def on_connect(client, userdata, flags, rc):
    print('connected with code' + str(rc))
    client.subscribe((mqtt_topic,0))
    client.subscribe((mqtt_topic1,0))    


def on_message(client, userdata, msg):
    payload = msg.payload
    print(msg.topic)
    print( payload)
    #print (processed)
    #print(float(str(msg.payload)))


def on_disconnect(self, client, userdata, rc):
    self.disconnected.set_result(rc)

  • Sign in to reply

Top Comments

  • embeddedguy
    embeddedguy over 4 years ago in reply to skruglewicz +1
    Thank you! Yes, MQTT is cool. No, they are just jumper wires like this. Luckily, I had enough of them!
  • embeddedguy
    embeddedguy over 4 years ago in reply to embeddedguy

    But I am not sure that MQTT can be an option in space.

    BLE can be more better

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • embeddedguy
    embeddedguy over 4 years ago in reply to skruglewicz

    Thank you!

    Yes, MQTT is cool.

    No, they are just jumper wires like this. Luckily, I had enough of them!

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 4 years ago

    I'm interested in experimenting with MQTT. I will follow your Blogs.

    One question... Did you Solder the hacker side of the header wires that connect to the Enviro

    Hat?

    • 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