I know this may not be the place to ask this question, but I figured someone here might be able to help, so I’m using a python script that came with my UPS:
#!/usr/bin/env python
import struct
import smbus
import sys
import time
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
return capacity
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
while True:
print "******************"
print "Battery:%5i%%" % readCapacity(bus)
if readCapacity(bus) == 100:
print "Battery FULL"
if readCapacity(bus) < 20:
print "Battery LOW"
print "******************"
time.sleep(2)
And I have a NodeJS app, in this app I have this code:
try {
let socVoltage = fs.readFileSync('/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/in_voltage0_input', 'utf8');
socVoltage = parseInt(socVoltage) / 1000.0;
socVoltage = `${socVoltage.toFixed(3)} V`;
sensors['Voltage'] = socVoltage;
} catch(err) {};
Is there a way I can get what the Python script is getting for capacity
into my NodeJS app in a similar way? I’m basically trying to not use python and just let my NodeJS app handle it.
Thanks in advance,
-b3ck