Hoang Bach in Discussions
上次活动时间: 2024-4-16

Hey, so I have a simple air quality measurement IoT system but the values are not arriving in my ThingSpeak channel. I use basic tutorials for it and tried some kind of variation but the code is so simple, I don't see any problem code-wise. Maybe someone here can help me? I am working with a Raspberry Pi 3 and the following code for a SDS011 sensor: import time from datetime import datetime import paho.mqtt.publish as publish import paho.mqtt.client as mqtt import psutil from sds011 import * import aqi sensor = SDS011("/dev/ttyUSB0", use_query_mode=True) def get_data(n=3): sensor.sleep(sleep=False) pmt_2_5 = 0 pmt_10 = 0 time.sleep(10) for i in range (n): x = sensor.query() pmt_2_5 = pmt_2_5 + x[0] pmt_10 = pmt_10 + x[1] time.sleep(2) pmt_2_5 = round(pmt_2_5/n, 1) pmt_10 = round(pmt_10/n, 1) sensor.sleep(sleep=True) time.sleep(2) return pmt_2_5, pmt_10 def conv_aqi(pmt_2_5, pmt_10): aqi_2_5 = aqi.to_iaqi(aqi.POLLUTANT_PM25, str(pmt_2_5)) aqi_10 = aqi.to_iaqi(aqi.POLLUTANT_PM10, str(pmt_10)) return aqi_2_5, aqi_10 def save_log(): with open("/YOUR PATH/air_quality.csv", "a") as log: dt = datetime.now() log.write("{},{},{},{},{}\n".format(dt, pmt_2_5, aqi_2_5, pmt_10, aqi_10)) log.close() channelID = "YOUR CHANNEL ID" apiKey = "YOUR WRITE KEY" clientID = "YOUR CLIENT ID" tUsername = "YOUR USERNAME" tPassword = "YOUR PASSWORD" topic = "channels/" + channelID + "/publish/" + apiKey mqttHost = "mqtt3.thingspeak.com" tTransport = "tcp" tPort = 1883 tTLS = None tProtocol = mqtt.MQTTv311 while True: pmt_2_5, pmt_10 = get_data() aqi_2_5, aqi_10 = conv_aqi(pmt_2_5, pmt_10) print ("AQI2.5 =", aqi_2_5," AQI10 =", aqi_10) tPayload = "field1=" + str(pmt_2_5)+ "&field2=" + str(aqi_2_5)+ "&field3=" + str(pmt_10)+ "&field4=" + str(aqi_10) try: publish.single(topic, payload=tPayload, hostname=mqttHost, port=tPort, client_id=clientID, auth={'username':tUsername, 'password':tPassword}, tls=tTLS, transport=tTransport, protocol=tProtocol) print ("[INFO] Published data") save_log() time.sleep(60) except Exception as e: print ("[INFO] Failure in sending data") print (e) time.sleep(60) Publish via Paho-MQTT publish.single but data is not arriving? Have a look at the documentation for MQTT and the provided examples. You are using syntax from the old broker, which was replaced in July 2021 and deprecated in April. Here is the new publish syntax for publish. The topic you are publishing to is incorrect. Take a look at the examples Christopher has linked to. So is this page in your documentation outdated then: https://se.mathworks.com/help/thingspeak/use-raspberry-pi-board-that-runs-python-websockets-to-publish-to-a-channel.html? Is there any way to use paho_mqtt to publish data in ThingSpeak or is the only option to use MQTT X? The code you reference should work. You can definitely still use paho, im pretty sure ive done it already on a pi. Just set up am MQTT device on the thingSpeak web UI, enable publishing from that device to your channel of interest, and copy the credentials to the pi. Can you tell us where it is failing for you? Now I found it: one extra /. Had f"channels/{channel_ID}/publish/ instead of f"channels/{channel_ID}/publish Damn, it was hard to find it. :P Thanks for help anyway! Ive had that one before, sorry I didnt look close enough to see that. We appreciate you sharing the solution! If its working, can you share an interesting plot from your monitor to inspire others who see this discussion? publish mqtt paho-mqtt air-quality sds011 raspberry pi 3
Christopher Stapels in Discussions
上次活动时间: 2022-1-18

My dear friend Ram and I have finished our latest movie series. You can watch the <https://www.mathworks.com/videos/iot-from-data-to-action-part-4-act-on-data-in-thingspeak-1639722099578.html final movie> , or see the <https://www.mathworks.com/videos/series/iot-from-data-to-action.html whole series>. In this movie we show how you can use TimeControls and Reacts to control devices or to schedule your MATLAB code that you can write in ThingSpeak. We also discuss a bit about channel sharing. New Movie: Act on Data in ThingSpeak. Fourth in IoT from Data to Action Thanks a lot for the movie. It turned out to be very helpful and instructive. Gratitude! move iot video environmental monitor air quality
Christopher Stapels in Discussions
上次活动时间: 2021-11-23

The <https://www.mathworks.com/videos/series/iot-from-data-to-action.html third movie> in our new series is live. We focus on MATLAB Analysis and Visualizations in this video. You can see how to set up code to preprocess your data and how to add custom visualizations. IoT from Data to Action: Part 3 video project environmental monitor air quality
Christopher Stapels in Discussions
上次活动时间: 2021-3-4

I've been working with several collaborators on an indoor air quality monitoring project. You can see the post at <https://www.hackster.io/team-matlab-iot/make-your-air-safer-alerting-indoor-iot-air-quality-monitor-5eb90d Hackster> . It would be interesting to deploy many of these throughout a building to investigate interactions between different rooms and the flow of people. So far I've got two in my house. Let us know if you plan to make a few of them. Air Quality monitoring: perhaps a good project for schools returning from hybrid model air quality iot arduino matlab hardware
Christopher Stapels in Discussions
上次活动时间: 2021-2-7

I'm presently working on an Air Quality monitor to be able to check the status of my environment and remote environments on ThingSpeak. I was planning on using the BME680 sensor. Does anyone have any experience with this or other air quality sensors? I'm looking probably for CO2 and the like (Volatile Organics), not so much particle sensors, though a combination may be best. What's your favorite air quality sensor? Every low-cost air quality sensor I come across is particle based. If you find a cheap CO2 sensor, I would be interested. CO2 is an important indicator of indoor air quality. Laboratory grade CO2 sensors cost around $50 or so. There are "equivalent" CO2 sensors based on the SGP30 that cost in the $15-20 range. I use ccs811 which needs I2C clock stretching and thus works well with Arduino like boards. It collects VTOC data and calculates eCO2. Great, thanks for sharing air quality environmental sensor thingspeak iot bme680

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.