To read the values in particular format using RevPi as Modbus RTU.

Topics about the Software of Revolution Pi
Post Reply
Anil
Posts: 41
Joined: 24 Jul 2019, 09:13
Answers: 0

To read the values in particular format using RevPi as Modbus RTU.

Post by Anil »

Dear Kunbus team,

We are reading the value from energy meter using RevPi as Modbus RTU master and later we want to transfer the same to the cloud using the MQTT.
We are able to read the value on the terminal using the piTest - r 11,16,d/h/b.

But when we read the same values on the Modscan Simulator act as master(instead of RevPi ) we can read the same value in following format unsigned/integer/float(MSRF)/float(LSRF)/Double(LSRF)/Double(MSRF).

so 1. Can we read the same way (multiple above formats )on the terminal of the RevPi Modbus RTU master?
2. Can REVPIMODIO 2 is helpful for this, if so how?
User avatar
nicolaiB
KUNBUS
Posts: 869
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: To read the values in particular format using RevPi as Modbus RTU.

Post by nicolaiB »

Hi Anil,

ihmo it's not possible to change the datatype with piTest, but RevPiModIO could be used to archive this. Have a look into the replace_io function which allows you to specify the datatype of your variable.

Nicolai
Anil
Posts: 41
Joined: 24 Jul 2019, 09:13
Answers: 0

Re: To read the values in particular format using RevPi as Modbus RTU.

Post by Anil »

Thanks for your response nicolaiB,

Will you please provide an already established reference/example so we can understand and implement accordingly. As I don't have much experience of python coding to interact with an embedded device, so don't want the unwanted result that changes in Pictory configuration and Rasbain image.
User avatar
nicolaiB
KUNBUS
Posts: 869
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: To read the values in particular format using RevPi as Modbus RTU.

Post by nicolaiB »

Hi Anil,

I published a small example with the replace_io function & mqtt: https://gist.github.com/nbuchwitz/08cc2 ... da3c65454e

Nicolai
Anil
Posts: 41
Joined: 24 Jul 2019, 09:13
Answers: 0

Re: To read the values in particular format using RevPi as Modbus RTU.

Post by Anil »

Thanks, Nicolai for your Response.

In a similar manner I had coded the MQTT protocol in python already and by importing the revpimodio2 and can able to read theInput_Word_1 but yes not use the .replace_io().

Code: Select all

################################################################################
# This script send the data from pin of RevPi Connect +Modbus TCP master as virtual 
# expansion module to the CloudMQTT Cloud (https://Cloudmqtt.com)
#
# Author- Rahul Chandarayan/Anil Sarode
################################################################################


import os, random    # The OS module in python provides functions for interacting with the operating system.
import time                                # Time module for python.
import sys   # The sys module provides information about constants, functions and methods of the Python interpreter
import paho.mqtt.client as mqtt            # The phao mqtt python client library
import json                                # java script object notation
import revpimodio2                         # To read the pins of revPi

HOST = 'farmer.cloudmqtt.com'
port=18989
USER_NAME = 'obvrnnss'
password="nZWKj6c8qas2"
TOPIC='v1/devices/me/telemetry'
INTERVAL=2

revpi = revpimodio2.RevPiModIO(autorefresh=True) # Instance to access to the IOs of the RevPiimport revpimodio2
sensor_data = {'temperature': 0, 'humidity': 0}
next_reading = time.time()
client = mqtt.Client()
client.username_pw_set(USER_NAME,password)
client.connect(HOST, port, 60)
client.loop_start()
try:
    while True:
        sensor_data['temperature'] =float(revpi.io.Input_Word_1.value)
        sensor_data['humidity'] = float(revpi.io.Input_Word_2.value)
        print(json.dumps(sensor_data))
        client.publish( TOPIC, json.dumps(sensor_data), 1)
        next_reading += INTERVAL
        sleep_time = next_reading-time.time()
        if sleep_time > 0:
            print (time.ctime())
            time.sleep(sleep_time)
            print (time.ctime())

except KeyboardInterrupt:
    pass
client.loop_stop()
client.disconnect()
Then what about this link: https://revolution.kunbus.de/forum/view ... =41&t=1306. In this what all those scripts and where we have to write those scripts. In this path replace_ios = /etc/revpipyload/replace_ios.conf what is the use of this .conf file ?

Even this link :https://revolution.kunbus.de/forum/view ... odio#p4817.
I am confused please guide me
User avatar
nicolaiB
KUNBUS
Posts: 869
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: To read the values in particular format using RevPi as Modbus RTU.

Post by nicolaiB »

Hi Anil,

you can define all your replaced IOs in a configuration file (ini style) and load it with revpimodio. So you don't have to hardcode everything in your program. For more details have a look into the documentation (https://revpimodio.org/en/doc2/) and Svens explanation in the linked threads.

Nicolai
Post Reply