Manira in MATLAB Answers
Letzte Aktivitätam 3 Feb. 2023

I have used the following code in Raspi 4. When I run the code it displays field1 and field2 on the screen. However my channel is not receiving any data. Writing Payload = field1=6.6&field2=17.2 to host: mqtt3.thingspeak.com clientID= xxxxxxxxxxxxxxxxxxxx User xxxxxxxxx PWD xxxxxxxxxxxxxxxx import paho.mqtt.publish as publish import psutil import string # The ThingSpeak Channel ID. # Replace <YOUR-CHANNEL-ID> with your channel ID. channel_ID = "xxxxxxxx" # The hostname of the ThingSpeak MQTT broker. mqtt_host = "mqtt3.thingspeak.com" # Your MQTT credentials for the device mqtt_client_ID = "xxxxxxxxxxxxxxxx" mqtt_username = "xxxxxxxxxxxxx" mqtt_password = "xxxxxxxxxxxxx" t_transport = "websockets" t_port = 80 # Create the topic string. topic = "channels/" + channel_ID + "/publish" while (True): # get the system performance data over 20 seconds. cpu_percent = psutil.cpu_percent(interval=20) ram_percent = psutil.virtual_memory().percent # build the payload string. payload = "field1=" + str(cpu_percent) + "&field2=" + str(ram_percent) # attempt to publish this data to the topic. try: print ("Writing Payload = ", payload," to host: ", mqtt_host, " clientID= ", mqtt_client_ID, " User ", mqtt_username, " PWD ", mqtt_password) publish.single(topic, payload, hostname=mqtt_host, transport=t_transport, port=t_port, client_id=mqtt_client_ID, auth={'username':mqtt_username,'password':mqtt_password}) except (keyboardInterrupt): break except Exception as e: print (e)

Info zu 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.