Nyheder:

Følg NBE Production A/S på
Facebook, se hvad vi laver :-)

Hovedmenu

V7/V13 UDP protocol client in python

Startet af motoz, Nov 30, 2015, 14:17

0 Brugere og 1 Gæst læser dette emne.

motoz

Jens told me that the new UDP protocol for local communication with the V7/13 box is nearing final, so if you have an updated V7 box you can try to talk to it with a test program I put up on github. It's written in python so it works on windows/mac/linux (and with some effort http://pythoncentral.io/python-for-android-the-scripting-layer-sl4a/ on android).  The test code implements a simple command line client that sends one request to the controller and prints the response.

https://github.com/motoz/nbetest

Use like this:

python client.py -a address -p password functioncode payload
or
python client.py -v -a address -p password functioncode payload
for a more verbose output.

If the address is left out the controller is discovered automatically on the local network

NBE kindly provides a public test box on v7testbox.stokercloud.dk with password 6464111183 that I have used to test the code since I don't (yet) have a V7 controller.

Read some settings from the text box:
python client.py -a v7testbox.stokercloud.dk -p 6464111183 1 boiler.*

You need python installed which can be downloaded here https://www.python.org/downloads/windows/. Both 2.7 and 3.5 work fine.

Ask Jens "BoinkUser" for more details on the protocol if you are interested.
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

BoinkUser

Hi Motoz

Thats just splendid  8)

Works like a charm.

Yes, any questions just ask, we also have Android code and Java (PC/Mac/Linux you name it) code, that are free for any interested. Anyone particulary interested in iOS we also have that. But Motoz' code is also a good choice for your preferred platform.

Regards Jens


Version 13 styring, styret fra 22" tablet, Opop 418 kedel
Opvarmer 238 m2 (heraf 119 kælder)

motoz

Now I have a V7 box to play with...

Looks like the latest released (not beta) firmware has an older version of the protocol (no sequence numbers). I made a change to the nbetest client so it works with 7.0612 when using the --noseqnum option on the command line:


python client.py --noseqnum -p xxxxxxxxxx 4 *
time=22120
boiler_temp=22.2
smoke_temp=999.9
return_temp=999.9
dhw_temp=999.9
external_temp=999.9
forward_temp=999.9
t7_temp=999.9
distance=0
photo_level=0
shaft_temp=999.9
milli_ampere=0
oxygen=15.4
...


On linux and mac you need to escape the wildcard character '*' (otherwise the shell will expand it to filenames from the current directory):
python client.py --noseqnum -p xxxxxxxxxx 4 \*

This is fun... ;D
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

motoz

I fleshed out the test client a bit yesterday. Now there is a 'get' and a 'set' command and a 'raw' command to send raw frames as before.
$ python client.py get
settings/
operating_data/
advanced_data/
consumption_data/
event_log/


$ python client.py get settings
settings/boiler
settings/hot_water
settings/regulation
settings/weather
settings/oxygen
settings/cleaning
settings/hopper
settings/fan
settings/auger
settings/ignition
settings/pump
settings/sun
settings/vacuum
settings/misc
settings/alarm
settings/manual
settings/bbq_smoke
settings/bbq_rotation
settings/bbq_grill
settings/bbq_meat
settings/bbq_afterburner
settings/bbq_div


$ python client.py get settings/auger
settings/auger/forced_run=0
settings/auger/auger_capacity=2200
settings/auger/auto_calculation=1
settings/auger/auger_10=5.72
settings/auger/auger_50=12.9
settings/auger/auger_100=21.9
settings/auger/kw_min=6.0
settings/auger/kw_max=23
settings/auger/runs_minute=6
settings/auger/min_dose=5.0


$ python client.py get settings/auger/auger_capacity
2200


And set:
$ python client.py set settings/auger/auger_capacity 2300
OK


As you may have noticed the controller does not (yet?) check that the password supplied is correct so it can be skipped.
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

motoz

Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

g82

Looks nice, I could not get the client to work though.
My firmware is currently v7.0522, but I dont think it got sofar as to actually talk to it.

C:\Users\MORA\Downloads\nbetest-master>gui.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Particle\Tools\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call_
_
    return self.func(*args)
  File "C:\Users\MORA\Downloads\nbetest-master\gui.py", line 87, in OnButtonClic
k
    self.OnPressEnter(None)
  File "C:\Users\MORA\Downloads\nbetest-master\gui.py", line 96, in OnPressEnter

    self.text.insert(Tkinter.END, '\n'.join(self.proxy.get(path))+'\n\n')
  File "C:\Particle\Tools\Python27\lib\lib-tk\Tkinter.py", line 1898, in __getat
tr__
    return getattr(self.tk, attr)
AttributeError: proxy

C:\Users\MORA\Downloads\nbetest-master>client.py -n 1 boiler.*
usage: client.py [-h] [-v] [-a ADDRESS] [-p PASSWORD] [-n] {raw,set,get} ...
client.py: error: invalid choice: '1' (choose from 'raw', 'set', 'get')

C:\Users\MORA\Downloads\nbetest-master>client.py -n get 1 boiler.*
usage: client.py [-h] [-v] [-a ADDRESS] [-p PASSWORD] [-n] {raw,set,get} ...
client.py: error: unrecognized arguments: boiler.*

C:\Users\MORA\Downloads\nbetest-master>client.py -n get 1
Traceback (most recent call last):
  File "C:\Users\MORA\Downloads\nbetest-master\client.py", line 61, in <module>
    proxy = Proxy.discover(args.password, PORT, seqnums = not args.noseqnum)
  File "C:\Users\MORA\Downloads\nbetest-master\protocol.py", line 232, in discov
er
    return cls(password, port, addr='<broadcast>', seqnums=seqnums)
  File "C:\Users\MORA\Downloads\nbetest-master\protocol.py", line 146, in __init
__
    data, server = self.s.recvfrom(4096)
socket.timeout: timed out

C:\Users\MORA\Downloads\nbetest-master>




motoz

#6
You need at least 7.0612, I don't think there is any UDP protocol support at all in 7.0522. With 7.0612 it should work without sequence numbers, and above that with sequence numbers. The error exceptions are not handled at all in the test client, so when it does not work it just errors out as you noticed. Cool that you are testing it.
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

g82

Updates to v7.0612 today, but what is the correct command to get some data from it?
The python scripts to fail too fast for it to be actual network exchange with a host it needs to detect first.


motoz

With 7.0612 you have to add the option --noseqnum to the command line, eg:
python client.py --noseqnum get
returns:
settings/
operating_data/
advanced_data/
consumption_data/
event_log/
sw_versions/
info/


and
python client.py --noseqnum get settings
return:
settings/boiler/
settings/hot_water/
settings/regulation/
settings/weather/
settings/oxygen/
settings/cleaning/
settings/hopper/
settings/fan/
settings/auger/
settings/ignition/
settings/pump/
settings/sun/
settings/vacuum/
settings/misc/
settings/alarm/
settings/manual/
settings/bbq_smoke/
settings/bbq_rotation/
settings/bbq_grill/
settings/bbq_meat/
settings/bbq_afterburner/
settings/bbq_div/

and python client.py --noseqnum get settings/boiler

returns:
settings/boiler/temp=62
settings/boiler/diff_over=10
settings/boiler/diff_under=5
settings/boiler/reduction=10
settings/boiler/ext_stop_temp=0.0
settings/boiler/ext_stop_diff=1.0
settings/boiler/ext_switch=0
settings/boiler/ext_off_delay=1
settings/boiler/ext_on_delay=1
settings/boiler/timer=0
settings/boiler/monday=000000000000
settings/boiler/tuesday=000000000000
settings/boiler/wednesday=000000000000
settings/boiler/thursday=000000000000
settings/boiler/friday=000000000000
settings/boiler/saturday=000000000000
settings/boiler/sunday=000000000000

python client.py --noseqnum get settings/boiler/temp
returns only the temperature, and so on.

In the gui program you can type eg. 'get settings/boiler' in the input field and click the 'run command' button. The 'seqnums' checkbox need to be unselected on 7.0612

This is only for testing the protocol so far (which probably isn't still final), so it's not that useful yet but something to play with.

Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

g82

#9
Very nice and fast O0

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get
settings/
operating_data/
advanced_data/
consumption_data/
event_log/
sw_versions/
info/

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get settings
settings/boiler/
settings/hot_water/
settings/regulation/
settings/weather/
settings/oxygen/
settings/cleaning/
settings/hopper/
settings/fan/
settings/auger/
settings/ignition/
settings/pump/
settings/sun/
settings/vacuum/
settings/misc/
settings/alarm/
settings/manual/
settings/bbq_smoke/
settings/bbq_rotation/
settings/bbq_grill/
settings/bbq_meat/
settings/bbq_afterburner/
settings/bbq_div/

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get settings/boiler
settings/boiler/temp=70
settings/boiler/diff_over=15
settings/boiler/diff_under=10
settings/boiler/reduction=10
settings/boiler/ext_stop_temp=0.0
settings/boiler/ext_stop_diff=1.0
settings/boiler/ext_switch=0
settings/boiler/ext_off_delay=1
settings/boiler/ext_on_delay=0
settings/boiler/timer=0
settings/boiler/monday=220000000002
settings/boiler/tuesday=220000000002
settings/boiler/wednesday=220000000002
settings/boiler/thursday=220000000002
settings/boiler/friday=220000000002
settings/boiler/saturday=220000000002
settings/boiler/sunday=220000000002

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get settings/boiler
temp
70

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get operating_data
operating_data/time=22160
operating_data/boiler_temp=75.9
operating_data/smoke_temp=104.9
operating_data/return_temp=64.5
operating_data/dhw_temp=999.9
operating_data/external_temp=999.9
operating_data/forward_temp=999.9
operating_data/t7_temp=999.9
operating_data/distance=0
operating_data/photo_level=100
operating_data/shaft_temp=42.9
operating_data/milli_ampere=295
operating_data/oxygen=18.9
operating_data/flow1=0
operating_data/flow2=0
operating_data/flow3=0
operating_data/flow4=0
operating_data/power_pct=34
operating_data/power_kw=5.4
operating_data/oxygen_ref=20.9
operating_data/boiler_ref=70.0
operating_data/mean_out_temp=-0.7
operating_data/dhw_ref=0.0
operating_data/forward_ref=0.0
operating_data/sun2_temp=999.9
operating_data/sun_dhw_temp=999.9
operating_data/sun_surplus_temp=999.9
operating_data/air_flow=0
operating_data/content=54
operating_data/state=5
operating_data/substate=0
operating_data/boiler_pump_state=1
operating_data/dhw_valve_state=0
operating_data/house_pump_state=0
operating_data/house_valve_state=0
operating_data/sun_pump_state=0
operating_data/sun_surplus_state=0
operating_data/sun_power_kw=0.0
operating_data/chill_out=-0.7
operating_data/feed_low=4.20
operating_data/feed_medium=21.0
operating_data/feed_high=42.0
operating_data/internet_uptime=100
operating_data/off_on_alarm=1
operating_data/contact1=1
operating_data/contact2=0
operating_data/download_progress=1
operating_data/substate_sec=1
operating_data/corr_low=100.00
operating_data/corr_medium=100.00
operating_data/corr_high=100.00
operating_data/ash_clean=13.4
operating_data/compressor_clean=0.0
operating_data/fan_speed=12
operating_data/exhaust_speed=47
operating_data/output_std=20
operating_data/output_ext=0
operating_data/output_wireless=0
operating_data/city=Tyrsted
operating_data/humidity=92
operating_data/air_pressure=1001
operating_data/wind_speed=1.50
operating_data/wind_direction=30
operating_data/clouds=80
operating_data/outdoor_temp=-2.00

C:\Users\MORA\Downloads\nbetest-master>client.py --noseqnum get operating_data/boiler_temp
75.9



Image shows a Particle Photon subscribed to boiler temp updates from your python script via bash enabling 5second temperature updates :)

MortenEV

Godt arbejde, både til Jens og jer andre. UDP er rigtigt smart og det bliver spændende hvad løsninger som det kan blive til i fremtiden :-)
http://stokercloud.dk/dev/oestervang.html
RTB30 - Iltstyring - VVB - Komp rens - 10Pa Trækstabilisator
Opvarmer 305kvm (45% gulvarme) - 21 grader , forbrug ca. 14 tons

g82

After running every minute for a few days it failed today, is there anything I can do to debug it that would be useful ?



:~/nbetest$ ./client.py --noseqnum get operating_data
Traceback (most recent call last):
  File "./client.py", line 61, in <module>
    proxy = Proxy.discover(args.password, PORT, seqnums = not args.noseqnum)
  File "/home/mora/nbetest/protocol.py", line 232, in discover
    return cls(password, port, addr='<broadcast>', seqnums=seqnums)
  File "/home/mora/nbetest/protocol.py", line 146, in __init__
    data, server = self.s.recvfrom(4096)
socket.timeout: timed out

motoz

Did it fail just once? It says 'timeout', ie no answer. Could be a temporary network problem, or a glitch in the controller. There is no error handling int the test client, so it just quits with an unhandled exception on any problem.
Or did you upgrade the controller firmware?
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

g82

No It has been running in a crontab every minute, but has failed since around 2pm, I only just disabled the crontab since I was getting no sensor data and went to check on it.
Firmware is same as last, it was the latest I could select, v7.0612, not sure if there is a newer one now that I have upgraded.

The error will probably go away if I restart the boiler.

motoz

I remember Jens said that there was a problem like that in some version, it just died and needed a restart. It's possible it's still in 7.612, I don't remember when it was fixed.
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon