Lees X728 voltage en lading en stuur dit naar Domoticz

Gepubliceerd door Robot One op

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import struct
import smbus
import sys
import time
import requests
def readVoltage(bus):
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
voltage = swapped * 1.25 /1000/16
return voltage
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
if (capacity > 100):
capacity = 100
return capacity
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
voltage = "%.2f" % readVoltage(bus)
battery = "%i" % readCapacity(bus)
url = "http://127.0.0.1:8088/json.htm?type=command&param=udevice&idx=561&nvalue=0&svalue=" + voltage
r = requests.get(url)
print(r) # voor debuggen: resultaat moet 200 zijn = OK
url = "http://127.0.0.1:8088/json.htm?type=command&param=udevice&idx=562&nvalue=0&svalue=" + battery
r = requests.get(url)
print(r) # voor debuggen: resultaat moet 200 zijn = OK
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Categorieën: