Forfatter Emne: V7/V13 UDP protocol client in python  (Læst 128073 gange)

0 Medlemmer og 3 Gæster læser dette emne.

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
V7/V13 UDP protocol client in python
« Dato: Nov 30, 2015, 14:17 »
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:

Kode: [Vælg]
python client.py -a address -p password functioncode payloador
Kode: [Vælg]
python client.py -v -a address -p password functioncode payloadfor 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:
Kode: [Vælg]
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

Offline BoinkUser

  • Administrator
  • Top of the pop
  • *****
  • Indlæg: 2148
  • Respekt optjent: +83/-4
    • StokerKontrol - Software til dit pillefyr
Sv: V7/V13 UDP protocol client in python
« Svar #1 Dato: Dec 01, 2015, 11:02 »
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)

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #2 Dato: Dec 09, 2015, 18:05 »
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:

Kode: [Vælg]
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):
Kode: [Vælg]
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

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #3 Dato: Dec 14, 2015, 06:30 »
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.
Kode: [Vælg]
$ python client.py get
settings/
operating_data/
advanced_data/
consumption_data/
event_log/

Kode: [Vælg]
$ 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

Kode: [Vælg]
$ 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

Kode: [Vælg]
$ python client.py get settings/auger/auger_capacity
2200

And set:
Kode: [Vælg]
$ 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

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #4 Dato: Dec 14, 2015, 18:44 »
Added a small gui to the test code (gui.py)



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

Offline g82

  • Øvet
  • **
  • Indlæg: 20
  • Respekt optjent: +0/-0
Sv: V7/V13 UDP protocol client in python
« Svar #5 Dato: Jan 07, 2016, 18:59 »
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.

Kode: [Vælg]
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>




Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #6 Dato: Jan 07, 2016, 20:35 »
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.
« Senest Redigeret: Jan 07, 2016, 20:36 af motoz »
Bio Comfort 30kW, compressor cleaning, lambda. Termax 25cr boiler. Matene vertical pellet conveyor. PellMon open source pellet logger: https://github.com/motoz/PellMon

Offline g82

  • Øvet
  • **
  • Indlæg: 20
  • Respekt optjent: +0/-0
Sv: V7/V13 UDP protocol client in python
« Svar #7 Dato: Jan 08, 2016, 18:32 »
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.


Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #8 Dato: Jan 08, 2016, 21:28 »
With 7.0612 you have to add the option --noseqnum to the command line, eg:
Kode: [Vælg]
python client.py --noseqnum getreturns:
Kode: [Vælg]
settings/
operating_data/
advanced_data/
consumption_data/
event_log/
sw_versions/
info/

and
Kode: [Vælg]
python client.py --noseqnum get settingsreturn:
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
Kode: [Vælg]
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

Kode: [Vælg]
python client.py --noseqnum get settings/boiler/tempreturns 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

Offline g82

  • Øvet
  • **
  • Indlæg: 20
  • Respekt optjent: +0/-0
Sv: V7/V13 UDP protocol client in python
« Svar #9 Dato: Jan 08, 2016, 22:04 »
Very nice and fast O0

Kode: [Vælg]
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 :)
« Senest Redigeret: Jan 08, 2016, 22:22 af g82 »

Offline MortenEV

  • Top of the pop
  • *****
  • Indlæg: 178
  • Respekt optjent: +3/-0
    • Link til stokercloud
Sv: V7/V13 UDP protocol client in python
« Svar #10 Dato: Jan 11, 2016, 10:17 »
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

Offline g82

  • Øvet
  • **
  • Indlæg: 20
  • Respekt optjent: +0/-0
Sv: V7/V13 UDP protocol client in python
« Svar #11 Dato: Jan 18, 2016, 19:15 »
After running every minute for a few days it failed today, is there anything I can do to debug it that would be useful ?


Kode: [Vælg]
:~/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

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #12 Dato: Jan 18, 2016, 19:38 »
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

Offline g82

  • Øvet
  • **
  • Indlæg: 20
  • Respekt optjent: +0/-0
Sv: V7/V13 UDP protocol client in python
« Svar #13 Dato: Jan 18, 2016, 19:42 »
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.

Offline motoz

  • Top of the pop
  • *****
  • Indlæg: 255
  • Respekt optjent: +18/-0
Sv: V7/V13 UDP protocol client in python
« Svar #14 Dato: Jan 18, 2016, 19:56 »
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