For future reference, when posting code or bash output, please put in 3 ābackticksā (found at the top left of the keyboard normally) on a line on their own, then the code, then 3 more backticks on a line following the code.
```
code
```
If it is something like php you can add a language identifier that after the first 3 backticks so ```php
emoncms.org and emonCMS run locally are not identical software. Therefore, the facilities available differ, there are also constraints caused by it being multi-user and publicly accessible.
There were two problems with the code from GitHub - karioja/vedirect: Simple VE.Direct reader for Python: 1) HTTPS connections are not supported for emonpi though python reports a good initial connection that then fails during the post; 2) data must be numerical.
I have reworked a section of code for an HTTP connection rather than HTTPS and added error/exception handling so that failures are reported properly. I also replace some alpha values with numbers. Looks like more work may be required for other Victron models other than the BMV-700 around non-numeric data.
def print_data_callback(data):
data=repr(data)
data = data.replace ( " ", "" ) # no spaces allowed
data = data.replace ( "OFF", "0" )
data = data.replace ( "ON", "1" )
data = data.replace ( "x", "0" )
print ( data )
try:
conn = httplib.HTTPConnection(domain)
except Exception as ex:
# print ( "Failed connecting to " + domain )
print ( "Connect Exception: {}".format(type(ex).__name__))
print ( "Connect Exception: {}".format ( ex ))
sys.exit(1)
else:
print ( "Connected to " + domain )
try:
conn.request("POST", baseurl+data)
r1 = conn.getresponse()
msg = unicode ( r1.read(), "UTF-8" )
print r1.status, r1.reason, msg
except Exception as ex:
print("Failed uploading data")
print ( "Post Exception: {}".format(type ( ex ).__name__))
print ( "Post Exception: {}".format ( ex ))
sys.exit(1)
else:
# print("Uploaded data OK")
sys.exit(0)
#time.sleep(60)