GithubHelp home page GithubHelp logo

python libmbus about libmbus HOT 9 CLOSED

rscada avatar rscada commented on August 23, 2024
python libmbus

from libmbus.

Comments (9)

kamaxeon avatar kamaxeon commented on August 23, 2024

Hi cibermailer,

Could you test this code ?

#!/usr/bin/env python
from xml.dom import minidom
import subprocess


def read_meter(bus_id):
    # Retrieve the XML data
    cmd = ['mbus-serial-request-data', '-b', '2400', ' /dev/serial0', str(bus_id)]
    reqdata = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    mbus_xml, err = reqdata.communicate()
    if err:
        raise SystemExit, '\nERROR: "' + ' '.join(cmd) + '" returned "' + err + '"'
    try:
        return minidom.parseString(mbus_xml)
    except:
        raise SystemExit, '\nERROR: Problem parsing M-Bus XML:\n"' + mbus_xml


if __name__ == '__main__':
    result = read_meter(10)
    print(result.toxml())

from libmbus.

cybermailer avatar cybermailer commented on August 23, 2024

I created a file test.py on Documents folder. Set chmod a+x on this file. Runned this file by
python test.py also sudo test.py...

I'm getting this error:

ERROR: "mbus-serial-request-data -b 2400 /dev/serial0 10" returned "mbus_serial_connect: failed to open tty.Failed to setup connection to M-bus gateway "
But i can do on command line this:
mbus-serial-request-data -b 2400 /dev/serial0 10
without any problem...

from libmbus.

cybermailer avatar cybermailer commented on August 23, 2024

ohhh is this raspi 3 problem because of disabled access from login shell? ...i give it a try --> IT WASN'T ... so problem exists...have i anything do previous that this communication will work?

from libmbus.

cybermailer avatar cybermailer commented on August 23, 2024

I've read a lot now -> can it be that there is some kind of problem because of:

non-ASCII characters (e.g., French or German OR some kind of timing OR Python Bug because with php it works on my raspberry 3 (raspbian).

ALSO:

your posts script does not make my slave led on Relay PW3 going on. Therefore there is realy no request to it.

My script makes the slave led going on and receiving data...i have both scripts checked but cannot find what can cause that error on your script...

On my script i'm now getting this:
[2017-07-26 14:00:39] SEND (005): 10 40 FD 3D 16 [2017-07-26 14:00:40] SEND (005): 10 40 FD 3D 16 [2017-07-26 14:00:40] SEND (005): 10 5B 0A 65 16 [2017-07-26 14:00:41] RECV (136): 68 82 82 68 08 0A 72 10 00 00 00 2D 2C 01 04 58 00 00 00 0C 07 50 77 40 00 0C 16 03 52 08 00 0C 22 67 17 03 00 0C 59 82 76 00 00 0C 5D 77 49 00 00 0C 61 05 27 00 00 0C 2E 67 00 00 00 0C 3C 15 02 00 00 4C 07 10 71 32 00 4C 16 51 85 06 00 42 6C 1F 2C 0F 10 00 00 00 00 00 63 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 58 41 04 00 00 00 00 02 26 07 17 00 64 16 Traceback (most recent call last): File "test.py", line 13, in <module> mbusdata = minidom.parseString(output) File "/usr/lib/python2.7/xml/dom/minidom.py", line 1928, in parseString return expatbuilder.parseString(string) File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString return builder.parseString(string) File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString parser.Parse(string, True) xml.parsers.expat.ExpatError: syntax error: line 1, column 0

from libmbus.

kamaxeon avatar kamaxeon commented on August 23, 2024

I do not think this will help, but you can try putting the utf8 encoding in the file.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

Could you print the output and error variable ??

from libmbus.

cybermailer avatar cybermailer commented on August 23, 2024

the returning mbus frame is correct (the hex) ... on bash the hex code is the same like in python.

On bash libmbus does concert the frame automatically. With this function: mbus_frame_print: Dumping M-Bus frame [type 4, 136 bytes]

Calling mbus from python does only give the hex code. this error:

xml.parsers.expat.ExpatError: syntax error: line 1, column 0

should mean there is something wrong, or that the hex can't be handled...some information on the ned do something like wrapping the output: + output +

i'm little confused...is there a way to transform the hex to human readable content stuff?

from libmbus.

lategoodbye avatar lategoodbye commented on August 23, 2024

Yes, the test directory contains the program mbus_parse_hex, which isn't compiled per default. So you must call make within the test directory.

from libmbus.

tnrajvignesh avatar tnrajvignesh commented on August 23, 2024

Hi,
I managed to get the libmbus library compiled and working on my pi.
I would like to use the python wrapper here
to develop my Mbus scanner application on Python.
The example code is here

In the example code, I see an Mbus instance being initialised in line 16
mbus = MBus(host="mbus-gw1", port=8888)

I would like to have Mbus on serial port /dev/TTYAMA0.
Please guide me on initialising Mbus on the serial port instead of TCP.

from libmbus.

lategoodbye avatar lategoodbye commented on August 23, 2024

Your question isn't specific to libmbus. Please create a new issue in python-mbus repo.

from libmbus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.