Contenido principal

Resultados de

Dears Good day. I am new in IoT and I need help I am looking for a code that I can run to transmit real-time data from Revolution Pi based on Raspberry Pi to Thingspeak. I have code I used before to transmit data from Revolution Pi based on Raspberry Pi to Wolkabout ( cloud platform). Nevertheless, due to license issues. I had to change to Thingspeak. Can you please help me to adjust the code so that I can use it with Thingspeak instead of Wolkabout. Here is the code .............Code start...............

import os
import random
import sys
import time
from urllib.request import urlopen
import wolk 
import revpimodio2
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.register_read_message import ReadInputRegistersResponse
  1. Sensors Keys device = wolk.Device(key="KDD", password="FDV7F12TSW")

wolk_device = wolk.WolkConnect(device, host="54.72.159.61", port=8883, ca_cert="ca_local_wolkabout.crt") # Establish a connection to the WolkAbout IoT Platform print("Connecting to WolkAbout IoT Platform") wolk_device.connect() rpi = revpimodio2.RevPiModIO(autorefresh=True)

  1. For Modbus RTU Connection #client = ModbusClient(method = 'rtu', port='/dev/ttyRS485', stopbits=1, bytesize=8, parity='E',baudrate=19200,timeout=1,strict=False) #connection = client.connect() #print(connection)

def main(): """Connect to WolkAbout IoT Platform and send a random sensor reading."""

    publish_period_seconds = 5
    # LS1 Level sensor 1 LS2 Level sensor 2 VS1 Velocity sensor 1 VS2 Velocity sensor 2
    while True:
        try:
            #first set of the sensors
            LS1 = rpi.io.InputValue_1.value*0.059056-205.825
            LS2 = rpi.io.InputValue_2.value*0.059056-205.825
            VS1 = rpi.io.InputValue_3.value*0.0025-10
            VS2 = rpi.io.InputValue_4.value*0.0025-10
            #sensors from RTU1
            #Temp1= (client.read_input_registers(58, 1, unit=1))
            #Temp2 = Temp1.registers
            #Temp = float(Temp2[0])/100
            Temp1 = rpi.io.Temperature.value/100
            Temp2 = rpi.io.Temperature2.value/100
            #mu1= (client.read_input_registers(66, 1, unit=1))
            #mu2 = mu1.registers
            #mu = float(mu2[0])/100
            mu1 = rpi.io.Viscosity.value/100
            mu2 = rpi.io.Viscosity2.value/100
            #rho1= (client.read_input_registers(74, 1, unit=1))
            #rho2 = rho1.registers
            #rho = float(rho2[0])/100
            rho1 = rpi.io.Density.value/100
            rho2 = rpi.io.Density2.value/100
            #publshing data
            #wolk_device.add_sensor_readings({"LS1": LS1,"LS2": LS2,"VS1": VS1,"VS2": VS2,"Temp1": Temp1,"rho1": rho1,"mu1": mu1,"Temp2": Temp2,"rho2": rho2,"mu2": mu2})
            print('Publishing "Level Sensor 1": ' + str(LS1))
            print('Publishing "Level Sensor 2": ' + str(LS2))
            print('Publishing "Velocity Sensor 1": ' + str(VS1))
            print('Publishing "Velocity Sensor 2": ' + str(VS2))
            print('Publishing "Temperature_RTU1": ' + str(Temp1))
            print('Publishing "Viscosity_RTU1": ' + str(mu1))
            print('Publishing "Density_RTU1": ' + str(rho1))
            print('Publishing "Temperature_RTU2": ' + str(Temp2))
            print('Publishing "Viscosity_RTU2": ' + str(mu2))
            print('Publishing "Density_RTU2": ' + str(rho2))
            #wolk_device.publish()
            time.sleep(publish_period_seconds)
        except KeyboardInterrupt:
            print("\tReceived KeyboardInterrupt. Exiting script")
            wolk_device.disconnect()
            sys.exit()

if _name_ == "__main__": main() ...............Code End................... Hope that you can help me. I have a fee account in Thingspeak, only 1 channel with 8 fields which is enough for my current project for time being. Wish you a nice day