Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbustcp fix #152

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions conf/emonpi.default.emonhub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ loglevel = DEBUG
calibration = 230V # (UK/EU: 230V, US: 110V)
quiet = true # Disable quite mode (default enabled) to enable RF packet debugging, show packets which fail crc
# interval = 300 # Interval to transmit time to emonGLCD (seconds)


[[MQTT]]

Expand Down Expand Up @@ -137,7 +137,7 @@ loglevel = DEBUG
datacodes = h,h,h,h,h,h,h,h,h,h,h,L
scales = 1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
units = W,W,W,W,V,C,C,C,C,C,C,p

[[12]]
nodename = 3phase2
[[[rx]]]
Expand Down Expand Up @@ -242,4 +242,4 @@ loglevel = DEBUG
names = temperature, external temperature, humidity, battery, pulsecount
datacodes = h,h,h,h,L
scales = 0.1,0.1,0.1,0.1,1
units = C,C,%,V,p
units = C,C,%,V,p
6 changes: 3 additions & 3 deletions conf/interfacer_examples/DS18B20/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This EmonHub interfacer can be used to read directly from DS18B20 temperature se
3\. Exit and reboot the Pi

sudo reboot

4\. SSH back in again and run the following to enable the required modules:

sudo modprobe w1-gpio
Expand All @@ -25,8 +25,8 @@ This EmonHub interfacer can be used to read directly from DS18B20 temperature se

Login to the local copy of Emoncms running on the emonPi/emonBase and navigate to Setup > EmonHub. Click on 'Edit Config' and add the following config in the interfacers section to enable reading from the temperature sensors.

- **read_interval:** Interval between readings in seconds.
- **ids:** This can be used to link specific sensors addresses to input names listed under the names property.
- **read_interval:** Interval between readings in seconds.
- **ids:** This can be used to link specific sensors addresses to input names listed under the names property.
- **names:** Names associated with sensor id's, ordered by index.

Example DS18B20 EmonHub configuration:
Expand Down
2 changes: 1 addition & 1 deletion conf/interfacer_examples/Pulse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This EmonHub interfacer can be used to read directly from pulse counter connecte

- **pulse_pin:** Pi GPIO pin number must be specified. Create a second interfacer for more than one pulse sensor
- **Rate_limit:** The rate in seconds at which the interfacer will pass data to emonhub for sending on. Too short and pulses will be missed. Pulses are accumulated in this period.
- **nodeoffset:** Default NodeID is 0. Use nodeoffset to set NodeID
- **nodeoffset:** Default NodeID is 0. Use nodeoffset to set NodeID

Example Pulse counting EmonHub configuration:

Expand Down
2 changes: 1 addition & 1 deletion conf/interfacer_examples/Renogy/Renogy.emonhub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
names = BatteryPercent,Charging_Stage,BatteryTemp_F,SolarVoltage,SolarCurrent,SolarPower
datacode = 0
scales = 1, 1, 1, 0.1,0.01,1,1
units = %, s, s, V, A,W
units = %, s, s, V, A,W
2 changes: 1 addition & 1 deletion conf/interfacer_examples/graphite/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Ex: `<prefix>.emonPi.power1`
prefix = emonpi
```

With this config in place now you simply need to restart emonhub on your emonpi by ssh'ing into it and typing
With this config in place now you simply need to restart emonhub on your emonpi by ssh'ing into it and typing

$> sudo service emonhub restart

Expand Down
10 changes: 5 additions & 5 deletions conf/interfacer_examples/modbus/modbusTCP.emonhub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ loglevel = DEBUG
# Information here is designed for Fronius Symo 3 phase inverter.
Type = EmonModbusTcpInterfacer
[[[init_settings]]]
modbus_IP = 192.168.1.10 # ip address of client to retrieve data from
modbus_port = 502 # Portclient listens on
modbus_IP = 192.168.1.10 # ip address of client to retrieve data from
modbus_port = 502 # Portclient listens on
[[[runtimesettings]]]
# List of starting registers for items listed above
register = 40118,40092,40102,502,40285,40305,40284,40304,40086,40088,40090
register = 40118,40092,40102,502,40285,40305,40284,40304,40086,40088,40090
# nodeid used to match with node definition in nodes section below. Can be set to any integer value not previously used.
nodeId = 12
nodeId = 12
# Channel to publish data to should leave as ToEmonCMS
pubchannels = ToEmonCMS,
# time in seconds between checks, This is in addition to emonhub_interfacer.run() sleep time of .01
Expand Down Expand Up @@ -63,7 +63,7 @@ loglevel = DEBUG
nodevar_format_enable = 1
nodevar_format_basetopic = emon/


#######################################################################
####################### Nodes #######################
#######################################################################
Expand Down
8 changes: 4 additions & 4 deletions conf/interfacer_examples/modbus/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ The rType and datacodes must match. Use the table below to assist.

### Sample interfacer config within emonhub.conf

Sample configuration for modbus TCP clients
Sample configuration for modbus TCP clients

```
[[ModbusTCP]]
# this interfacer retrieves register information from modbusTCP clients
[[ModbusTCP]]
# this interfacer retrieves register information from modbusTCP clients
# retrieve register information from modbus TCP documentation for your inverter.
Type = EmonModbusTcpInterfacer
[[[init_settings]]]
Expand All @@ -30,7 +30,7 @@ Sample configuration for modbus TCP clients
pubchannels = ToEmonCMS,
# time in seconds between checks, This is in addition to emonhub_interfacer.run() sleep time of .01
# use this value to set the frequency of data retrieval from modbus client
interval = 10
interval = 10
```

### Sample Node declaration in emonhub.conf
Expand Down
2 changes: 1 addition & 1 deletion conf/interfacer_examples/smilices/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Using the Wibeee mac-address, without colons, as node id.
units = W, W, W, W, Wh, Wh, Wh, Wh


With this config in place, you simply need to restart emonhub on our emonpi by ssh'ing into it and typing
With this config in place, you simply need to restart emonhub on our emonpi by ssh'ing into it and typing

$>sudo service emonhub restart
4 changes: 2 additions & 2 deletions conf/interfacer_examples/vedirect/mppt.vedirect.emonhub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
com_port = /dev/ttyUSB0
com_baud = 19200
toextract = V,VPV,PPV,I,IL,LOAD,Relay,H19,H20,H21,H22,H23,ERR,CS,FW,PID,HSDS
poll_interval = 10
poll_interval = 10
[[[runtimesettings]]]
nodeoffset = 9 #make sure this matches with nodename below
pubchannels = ToEmonCMS,
Expand All @@ -19,4 +19,4 @@
names = V,VPV,PPV,I,IL,LOAD,Relay,H19,H20,H21,H22,H23,ERR,CS,FW,PID,HSDS
datacode = 0
scales = 0.001,0.001,0.001,0.001,1,1,1,1,0.001,1,0.001,1,1,1,1,1,1,1
units = V,V,W,A,A,1,1,kWh,kWh,W,kWh,W,1,1,1,1,1,1
units = V,V,W,A,A,1,1,kWh,kWh,W,kWh,W,1,1,1,1,1,1
10 changes: 5 additions & 5 deletions conf/interfacer_examples/vedirect/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The VE.Direct protocol is as binary/ASCII [protocol](https://www.victronenergy.com/live/vedirect_protocol:faq) created and used by [Victron Energy](https://www.victronenergy.com/) for communication between and with their products.

This interfacer provides support for reading data from any Victron product that can use the VE.Direct protocol for inter-device communication. Currently this includes the BMV600, BMV700, Blue Solar MPPT, and Phoenix ranges.
This interfacer provides support for reading data from any Victron product that can use the VE.Direct protocol for inter-device communication. Currently this includes the BMV600, BMV700, Blue Solar MPPT, and Phoenix ranges.

Example configurations are provided for the BMV700 battery monitor and Blue Solar MPPT charge controller.

Expand All @@ -20,7 +20,7 @@ Each supported product has it's own set of data that can be read over VE.Direct
[[[init_settings]]]
com_port = /dev/ttyUSB0 # Where to find our device
com_baud = 19200 # Baud rate needed to decode
toextract = SOC,CE,TTG,V,I,Relay,Alarm
toextract = SOC,CE,TTG,V,I,Relay,Alarm
poll_interval = 10 # How often to get data in seconds
[[[runtimesettings]]]
nodeoffset = 9 #make sure this matches with nodename below
Expand All @@ -29,18 +29,18 @@ Each supported product has it's own set of data that can be read over VE.Direct
basetopic = emonhub/


# Followed by a corresponding Node declaration
# Followed by a corresponding Node declaration

[[9]] # This node name should be consistent with the nodeoffset parameter above
nodename = VictronBMV700
[[[rx]]]
names = SOC,CE,TTG,V,I,Relay,Alarm # Make sure this matches 'toextract' in interfacer definition above
datacode = 0 #no need to decode values
scales = 0.1,1,1,0.001,1,1,1 # Some scaling necassary
units = %,Ah,s,V,A,S,S
units = %,Ah,s,V,A,S,S


With this config in place you just need to restart emonhub on your emonPi by rebooting it or ssh'ing into it and typing
With this config in place you just need to restart emonhub on your emonPi by rebooting it or ssh'ing into it and typing

$>sudo service emonhub restart

Expand Down
2 changes: 1 addition & 1 deletion conf/nodes/10
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
datacode = h
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 #Firmware V1.6
units =W,W,W,W,V,C,C,C,C,C,C,p #FirmwareV1.6
#scales = 1,1,1,1,0.01,0.1 #Firmware =<V1.4 (un-comment)
#scales = 1,1,1,1,0.01,0.1 #Firmware =<V1.4 (un-comment)
#units =W,W,W,W,V,C #Firmware =<V1.4 (un-comment)
2 changes: 1 addition & 1 deletion conf/nodes/7
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
[[[rx]]]
names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
datacodes = h,h,h,h,h,h,h,h,h,h,h,L
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
units =W,W,W,W,V,C,C,C,C,C,C,p
4 changes: 2 additions & 2 deletions conf/nodes/8
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
[[[rx]]]
names = power1, power2, power3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
datacodes = h,h,h,h,h,h,h,h,h,h,h,L
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
units =W,W,W,W,V,C,C,C,C,C,C,p
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
units =W,W,W,W,V,C,C,C,C,C,C,p
2 changes: 1 addition & 1 deletion conf/nodes/9
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
datacode = h
scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1 #Firmware V1.6
units =W,W,W,W,V,C,C,C,C,C,C,p #FirmwareV1.6
#scales = 1,1,1,1,0.01,0.1 #Firmware =<V1.4 (un-comment)
#scales = 1,1,1,1,0.01,0.1 #Firmware =<V1.4 (un-comment)
#units =W,W,W,W,V,C #Firmware =<V1.4 (un-comment)
2 changes: 1 addition & 1 deletion conf/nodes/Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Script for automatically adding node decoders to emonhub.conf without over-writing existing nodes

Called by emonpi [emonhub update script](https://github.com/openenergymonitor/emonpi/blob/master/emonhubupdate)
Called by emonpi [emonhub update script](https://github.com/openenergymonitor/emonpi/blob/master/emonhubupdate)
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ usrdir=${DIR/\/emonhub/}
emonSD_pi_env=$1
if [ "$emonSD_pi_env" = "" ]; then
read -sp 'Apply raspberrypi serial configuration? 1=yes, 0=no: ' emonSD_pi_env
echo
echo
echo "You entered $emonSD_pi_env"
echo
# Avoid running apt update if install script is being called from the EmonScripts update script
Expand Down
2 changes: 1 addition & 1 deletion src/emonhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _update_settings(self, settings):
self._log.info("Deleting interfacer '%s'", name)
self._interfacers[name].stop = True
interfacers_to_delete.append(name)

for name in interfacers_to_delete:
del self._interfacers[name]

Expand Down
50 changes: 25 additions & 25 deletions src/interfacers/EmonHubDS18B20Interfacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ def __init__(self):
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
self._base_dir = '/sys/bus/w1/devices/'

def scan(self):
devices = glob.glob(self._base_dir + '28*')
sensors = []
for device in devices:
sensor = device.replace(self._base_dir,"")
sensor = device.replace(self._base_dir, "")
sensors.append(sensor)
return sensors

def _read_raw(self,sensor):
def _read_raw(self, sensor):
f = open(self._base_dir + sensor + '/w1_slave', 'r')
lines = f.readlines()
f.close()
return lines
def tempC(self,sensor):

def tempC(self, sensor):
lines = self._read_raw(sensor)
# retry = 0
while lines[0].strip()[-3:] != 'YES':
Expand All @@ -45,7 +45,7 @@ def tempC(self,sensor):
# retry += 1
# if retry==3: return False
return False

equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
Expand All @@ -71,56 +71,56 @@ def __init__(self, name):
# self._settings.update(self._defaults)

# Interfacer specific settings
self._DS18B20_settings = {'read_interval': 10.0,'nodename':'sensors','ids':[],'names':[]}
self._DS18B20_settings = {'read_interval': 10.0, 'nodename':'sensors', 'ids':[], 'names':[]}

self.ds = DS18B20()

self.next_interval = True


def read(self):
"""Read data and process

Return data as a list: [NodeID, val1, val2]

"""
if int(time.time())%self._settings['read_interval']==0:
if self.next_interval:

if int(time.time()) % self._settings['read_interval'] == 0:
if self.next_interval:
self.next_interval = False

c = Cargo.new_cargo()
c.names = []
c.realdata = []
c.nodeid = self._settings['nodename']
if self.ds:

if self.ds:
for sensor in self.ds.scan():
# Check if user has set a name for given sensor id
name = sensor
try:
index = self._settings['ids'].index(sensor)
if index<len(self._settings['names']):
if index < len(self._settings['names']):
name = self._settings['names'][index]
except ValueError:
pass

# Read sensor value
value = self.ds.tempC(sensor)

# Add sensor to arrays
c.names.append(name)
c.realdata.append(value)
c.realdata.append(value)

# Log output
self._log.debug(sensor+": "+name+" "+str(value))
self._log.debug(sensor + ": " + name + " " + str(value))

if len(c.realdata)>0:
if len(c.realdata) > 0:
return c

else:
self.next_interval = True

return False


Expand All @@ -131,7 +131,7 @@ def set(self, **kwargs):
setting = kwargs[key]
else:
setting = self._DS18B20_settings[key]

if key in self._settings and self._settings[key] == setting:
continue
elif key == 'read_interval':
Expand Down
2 changes: 1 addition & 1 deletion src/interfacers/EmonHubJeeInterfacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def read(self):
self._rx_buf = self._rx_buf + self._ser.readline().decode()
except UnicodeDecodeError:
return

# If line incomplete, exit
if '\r\n' not in self._rx_buf:
return
Expand Down
Loading