VBatt with CayenneLPP?
-
I'm trying to get the vbatt values from my Pysense with a FiPy to send the values out via Lora using the CayenneLPP, but the cayenne library has no references to vbatt. I have no idea how to go about adding the right code there. Any ideas??
In main.py
print( 'Acceleration:', li.acceleration(), ', Roll:', li.roll(), ', Pitch:', li.pitch(), ', Light:', lt.light(), ', Humidity:', si.humidity(), ', Temperature:', si.temperature(), ', Battery Voltage: ', py.read_battery_voltage() ) ## ADD DATA TO CAYENNELPP #lpp.add_accelerometer(1, li.acceleration()[0], li.acceleration()[1], li.acceleration()[2]) #lpp.add_gryrometer(1, li.roll(), li.pitch(), 0) #lpp.add_luminosity(1, lt.light()[0]) #lpp.add_luminosity(2, lt.light()[1]) #lpp.add_relative_humidity(1, si.humidity()) lpp.add_temperature(1, si.temperature()) lpp.add_vbatt(1, py.read_battery_voltage())Error:
AttributeError: 'CayenneLPP' object has no attribute 'add_vbatt'""" Source: https://github.com/simonqbs/cayennelpp-python """ import struct import math LPP_DIGITAL_INPUT = 0 # 1 byte LPP_DIGITAL_OUTPUT = 1 # 1 byte LPP_ANALOG_INPUT = 2 # 2 bytes, 0.01 signed LPP_ANALOG_OUTPUT = 3 # 2 bytes, 0.01 signed LPP_LUMINOSITY = 101 # 2 bytes, 1 lux unsigned LPP_PRESENCE = 102 # 1 byte, 1 LPP_TEMPERATURE = 103 # 2 bytes, 0.1°C signed LPP_RELATIVE_HUMIDITY = 104 # 1 byte, 0.5% unsigned LPP_ACCELEROMETER = 113 # 2 bytes per axis, 0.001G LPP_BAROMETRIC_PRESSURE = 115 # 2 bytes 0.1 hPa Unsigned LPP_GYROMETER = 134 # 2 bytes per axis, 0.01 °/s LPP_GPS = 136 # 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01 meter # Data ID + Data Type + Data Size LPP_DIGITAL_INPUT_SIZE = 3 # 1 byte LPP_DIGITAL_OUTPUT_SIZE = 3 # 1 byte LPP_ANALOG_INPUT_SIZE = 4 # 2 bytes, 0.01 signed LPP_ANALOG_OUTPUT_SIZE = 4 # 2 bytes, 0.01 signed LPP_LUMINOSITY_SIZE = 4 # 2 bytes, 1 lux unsigned LPP_PRESENCE_SIZE = 3 # 1 byte, 1 LPP_TEMPERATURE_SIZE = 4 # 2 bytes, 0.1°C signed LPP_RELATIVE_HUMIDITY_SIZE = 3 # 1 byte, 0.5% unsigned LPP_ACCELEROMETER_SIZE = 8 # 2 bytes per axis, 0.001G LPP_BAROMETRIC_PRESSURE_SIZE = 4 # 2 bytes 0.1 hPa Unsigned LPP_GYROMETER_SIZE = 8 # 2 bytes per axis, 0.01 °/s LPP_GPS_SIZE = 11 # 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01 meter class CayenneLPP: def __init__(self): self.buffer = bytearray() def get_buffer(self): return self.buffer def reset(self): self.buffer = bytearray() def get_size(self): return len(self.buffer) def add_temperature(self, channel, value): val = math.floor(value * 10); self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_TEMPERATURE)) self.buffer.extend(struct.pack('b', val >> 8)) self.buffer.extend(struct.pack('b', val)) def add_relative_humidity(self, channel, value): val = math.floor(value * 2) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_RELATIVE_HUMIDITY)) self.buffer.extend(struct.pack('b', val)) def add_digital_input(self, channel, value): self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_DIGITAL_INPUT)) self.buffer.extend(struct.pack('b', value)) def add_digital_output(self, channel, value): self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_DIGITAL_OUTPUT)) self.buffer.extend(struct.pack('b', value)) def add_analog_input(self, channel, value): val = math.floor(value * 100) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_ANALOG_INPUT)) self.buffer.extend(struct.pack('b', val >> 8)) self.buffer.extend(struct.pack('b', val)) def add_analog_output(self, channel, value): val = math.floor(value * 100) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_ANALOG_OUTPUT)) self.buffer.extend(struct.pack('b', val >> 8)) self.buffer.extend(struct.pack('b', val)) def add_luminosity(self, channel, value): self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_LUMINOSITY)) self.buffer.extend(struct.pack('b', value >> 8)) self.buffer.extend(struct.pack('b', value)) def add_presence(self, channel, value): self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_PRESENCE)) self.buffer.extend(struct.pack('b', value)) def add_accelerometer(self, channel, x, y, z): vx = math.floor(x * 1000) vy = math.floor(y * 1000) vz = math.floor(z * 1000) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_ACCELEROMETER)) self.buffer.extend(struct.pack('b', vx >> 8)) self.buffer.extend(struct.pack('b', vx)) self.buffer.extend(struct.pack('b', vy >> 8)) self.buffer.extend(struct.pack('b', vy)) self.buffer.extend(struct.pack('b', vz >> 8)) self.buffer.extend(struct.pack('b', vz)) def add_barometric_pressure(self, channel, value): val = math.floor(value * 10) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_BAROMETRIC_PRESSURE)) self.buffer.extend(struct.pack('b', val >> 8)) self.buffer.extend(struct.pack('b', val)) def add_gryrometer(self, channel, x, y, z): vx = math.floor(x * 100) vy = math.floor(y * 100) vz = math.floor(z * 100) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_GYROMETER)) self.buffer.extend(struct.pack('b', vx >> 8)) self.buffer.extend(struct.pack('b', vx)) self.buffer.extend(struct.pack('b', vy >> 8)) self.buffer.extend(struct.pack('b', vy)) self.buffer.extend(struct.pack('b', vz >> 8)) self.buffer.extend(struct.pack('b', vz)) def add_gps(self, channel, latitude, longitude, meters): lat = math.floor(latitude * 10000) lon = math.floor(longitude * 10000) alt = math.floor(meters * 100) self.buffer.extend(struct.pack('b', channel)) self.buffer.extend(struct.pack('b', LPP_GPS)) self.buffer.extend(struct.pack('b', lat >> 16)) self.buffer.extend(struct.pack('b', lat >> 8)) self.buffer.extend(struct.pack('b', lat)) self.buffer.extend(struct.pack('b', lon >> 16)) self.buffer.extend(struct.pack('b', lon >> 8)) self.buffer.extend(struct.pack('b', lon)) self.buffer.extend(struct.pack('b', alt >> 16)) self.buffer.extend(struct.pack('b', alt >> 8)) self.buffer.extend(struct.pack('b', alt)) -
It's up to you..both can do the job.
a) lpp.add_analog_input(1, py.read_battery_voltage())
or
b) lpp.add_analog_output(1, py.read_battery_voltage())
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login