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

sml_server: add a switch to exit after one packet #46

Closed
hmueller01 opened this issue Jan 23, 2018 · 9 comments
Closed

sml_server: add a switch to exit after one packet #46

hmueller01 opened this issue Jan 23, 2018 · 9 comments

Comments

@hmueller01
Copy link

Off topic I discussed in #29 with @msebald that sml_server is used by the @openhab project rule sml. At the moment sml_server.c is copied there and modified slightly. The main reason for the change is, that the program needs to stop after processing one packet. My idea is to add a switch to do that. Do I get support for this and how should the switch be called? E.g. "-s" for single?

@andig
Copy link

andig commented Jan 23, 2018

I would have appreciated openhab proposing changes here.

@devZer0
Copy link

devZer0 commented Jan 23, 2018

smartmeter-obis got such switch just recently. i would recommend everyone developing on libsml should have a look at that lib - just to have something to compare with

@msebald
Copy link

msebald commented Jan 24, 2018

Thank you for the new issue and that you are willing to include the needs of the openHAB people into libsml.

I just checked. In my case the unmodified sml_server produces the following output, which also loops:

SML file (3 SML messages, 316 bytes)
SML message  101
SML message  701
SML message  201
OBIS data
129-129:199.130.3*255#EMH#
1-0:0.0.9*255#06 45 4d 48 01 0b c1 a5 e7 2b #
1-0:1.8.0*255#20355093.1#Wh
1-0:1.8.1*255#20355093.1#Wh
1-0:1.8.2*255#0.0#Wh
1-0:16.7.0*255#592.3#W
129-129:199.130.5*255#T04 77 07 9e 79 9f 7c 4d 74 45 e0 b8 6b 6c fd 50 88 8a ab 9a 3a 5b 05 b8 4b fa d3 24 e1 f4 70 d1 30 39 e1 a4 93 23 18 9a 24 ec 3b ec c1 83 15 #

The modified sml_server produces the following output and then exists:

1-0:1.8.0*255#20234.615#
1-0:1.8.1*255#20234.615#
1-0:16.7.0*255#1.081#

So it it not just about a switch to terminate sml_server after a single run.

What I do not know exactly as my knowledge about Java (which is used for openHAB and also the linked rule) is basic: Does the unmodified sml_server output work? I would say no as it looks into all lines and makes something. Sorry that I cannot be more clear on that as I am really not a programmer...

@hmueller01
Copy link
Author

No, it will not work as it is. The rule just takes line 0 and 2, which won't work on all meters today. It needs to parse the lines it reads for 1.8.0 and 16.7.0. This should be quite simple.

@hmueller01
Copy link
Author

I made a branch which includes the -s. Please check, if this works. sml_server_switch
Please keep in mind that you still need to add a message parsing in the rule. This can not be done by sml_server.

@hmueller01
Copy link
Author

@msebald Did you have time to test my code?
I tried to change your rule to parse the object names:

		// getting the payload of the meter
		var String meter_payload = executeCommandLine("/home/openhabian/volkszaehler/libsml/examples/sml_server -s /dev/ttyUSB0", 5000) // note the argument /dev/ttyUSB0 or /dev/sml0 - your meter-device-id goes here
		// splitting the payload - first in lines, then getting counterStr and consumptionStr with delimiter "#"
		val lines = meter_payload.split('\n')
		for (String line : lines) {
			if (line != null) {
				// split the line separated into object name and value
				var lineStr = line.split('#')
				var obj_name = lineStr.get(0)
				var value = lineStr.get(1)
				if (obj_name == "1-0:1.8.0*255") {
					if (EHZ_status_power.state != value)
						EHZ_status_power.sendCommand(value)
				} else if (obj_name == "1-0:16.7.0*255") {
					EHZ_consumption_power.postUpdate(value)
				}
			}
		}

But be aware. I am not familiar in writing Xtend code and have not tested it with openHAB.

@msebald
Copy link

msebald commented Feb 9, 2018

No. But I will. I'm on vacation. Next week I'm back home again.

@hmueller01
Copy link
Author

@msebald Have you had a chance to test the code and the modified parsing? Just saw that this issue is still open.

@hmueller01
Copy link
Author

No answer from @msebald. But as I created a pull request, I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants