2
2
import paho .mqtt .client as mqtt
3
3
from cayenne import __version__
4
4
5
+
5
6
# Data types
6
- TYPE_ACCELERATION = "accel" # Acceleration
7
- TYPE_BAROMETRIC_PRESSURE = "bp" # Barometric pressure
8
- TYPE_BATTERY = "batt" # Battery
9
- TYPE_GPS = "gps" # GPS data
10
- TYPE_LUMINOSITY = "lum" # Luminosity
11
- TYPE_PROXIMITY = "prox" # Proximity
12
- TYPE_RELATIVE_HUMIDITY = "rel_hum" # Relative Humidity
13
- TYPE_TEMPERATURE = "temp" # Temperature
14
- TYPE_VOLTAGE = "voltage" # Voltage
7
+ TYPE_ACCELERATION = 'accel' # Acceleration, units: UNIT_G
8
+ TYPE_ANALOG_ACTUATOR = 'analog_actuator' # Analog Actuator, units: UNIT_ANALOG
9
+ TYPE_ANALOG_SENSOR = 'analog_sensor' # Analog Sensor, units: UNIT_ANALOG
10
+ TYPE_BAROMETRIC_PRESSURE = 'bp' # Barometric pressure, units: UNIT_PASCAL, UNIT_HECTOPASCAL
11
+ TYPE_BATTERY = 'batt' # Battery, units: UNIT_PERCENT, UNIT_RATIO, UNIT_VOLTS
12
+ TYPE_CO2 = 'co2' # Carbon Dioxide, units: UNIT_PPM
13
+ TYPE_COUNTER = 'counter' # Counter, units: UNIT_ANALOG
14
+ TYPE_CURRENT = 'current' # Current, units: UNIT_AMP, UNIT_MAMP
15
+ TYPE_DIGITAL_ACTUATOR = 'digital_actuator' # Digital Actuator, units: UNIT_DIGITAL
16
+ TYPE_DIGITAL_SENSOR = 'digital_sensor' # Digital Sensor, units: UNIT_DIGITAL
17
+ TYPE_ENERGY = 'energy' # Energy, units: UNIT_KWH
18
+ TYPE_EXT_WATERLEAK = 'ext_wleak' # External Waterleak, units: UNIT_ANALOG
19
+ TYPE_FREQUENCY = 'freq' # Frequency, units: UNIT_HERTZ
20
+ TYPE_GPS = 'gps' # GPS, units: UNIT_GPS
21
+ TYPE_GYROSCOPE = 'gyro' # Gyroscope, units: UNIT_ROTATION_PER_MINUTE, UNIT_DEGREE_PER_SEC
22
+ TYPE_LUMINOSITY = 'lum' # Luminosity, units: UNIT_LUX, UNIT_VOLTS, UNIT_PERCENT, UNIT_RATIO
23
+ TYPE_MOTION = 'motion' # Motion, units: UNIT_DIGITAL
24
+ TYPE_POWER = 'pow' # Power, units: UNIT_WATT, UNIT_KILOWATT
25
+ TYPE_PROXIMITY = 'prox' # Proximity, units: UNIT_CENTIMETER, UNIT_METER, UNIT_DIGITAL
26
+ TYPE_RAIN_LEVEL = 'rain_level' # Rain Level, units: UNIT_CENTIMETER, UNIT_MILLIMETER
27
+ TYPE_RELATIVE_HUMIDITY = 'rel_hum' # Relative Humidity, units: UNIT_PERCENT, UNIT_RATIO
28
+ TYPE_RESISTANCE = 'res' # Resistance, units: UNIT_OHM
29
+ TYPE_RSSI = 'rssi' # Received signal strength indicator, units: UNIT_DBM
30
+ TYPE_SNR = 'snr' # Signal Noise Ratio, units: UNIT_DB
31
+ TYPE_SOIL_MOISTURE = 'soil_moist' # Soil Moisture, units: UNIT_PERCENT
32
+ TYPE_SOIL_PH = 'soil_ph' # Soil pH, units: UNIT_ANALOG
33
+ TYPE_SOIL_WATER_TENSION = 'soil_w_ten' # Soil Water Tension, units: UNIT_KILOPASCAL, UNIT_PASCAL
34
+ TYPE_TANK_LEVEL = 'tl' # Tank Level, units: UNIT_ANALOG
35
+ TYPE_TEMPERATURE = 'temp' # Temperature, units: UNIT_FAHRENHEIT, UNIT_CELSIUS, UNIT_KELVIN
36
+ TYPE_VOLTAGE = 'voltage' # Voltage, units: UNIT_VOLTS, UNIT_MILLIVOLTS
37
+ TYPE_WIND_SPEED = 'wind_speed' # Wind Speed, units: UNIT_KM_PER_H
15
38
16
39
# Unit types
17
- UNIT_UNDEFINED = "null"
18
- UNIT_PASCAL = "pa" # Pascal
19
- UNIT_HECTOPASCAL = "hpa" # Hectopascal
20
- UNIT_PERCENT = "p" # % (0 to 100)
21
- UNIT_RATIO = "r" # Ratio
22
- UNIT_VOLTS = "v" # Volts
23
- UNIT_LUX = "lux" # Lux
24
- UNIT_CENTIMETER = "cm" # Centimeter
25
- UNIT_METER = "m" # Meter
26
- UNIT_DIGITAL = "d" # Digital (0/1)
27
- UNIT_FAHRENHEIT = "f" # Fahrenheit
28
- UNIT_CELSIUS = "c" # Celsius
29
- UNIT_KELVIN = "k" # Kelvin
30
- UNIT_MILLIVOLTS = "mv" # Millivolts
31
- UNIT_GRAVITY = "g" # Standard gravity
40
+ UNIT_UNDEFINED = 'null' # Undefined unit type
41
+ UNIT_AMP = 'a' # Ampere
42
+ UNIT_ANALOG = 'null' # Analog
43
+ UNIT_CELSIUS = 'c' # Celsius
44
+ UNIT_CENTIMETER = 'cm' # Centimeter
45
+ UNIT_DB = 'db' # Decibels
46
+ UNIT_DBM = 'dbm' # dBm
47
+ UNIT_DEGREE_PER_SEC = 'dps' # Degree per second
48
+ UNIT_DIGITAL = 'd' # Digital (0/1)
49
+ UNIT_FAHRENHEIT = 'f' # Fahrenheit
50
+ UNIT_G = 'g' # Acceleration
51
+ UNIT_GPS = 'm' # GPS
52
+ UNIT_HECTOPASCAL = 'hpa' # Hectopascal
53
+ UNIT_HERTZ = 'hz' # Hertz
54
+ UNIT_KELVIN = 'k' # Kelvin
55
+ UNIT_KILOPASCAL = 'kpa' # Kilopascal
56
+ UNIT_KILOWATT = 'kw' # Kilowatts
57
+ UNIT_KM_PER_H = 'kmh' # Kilometer per hour
58
+ UNIT_KWH = 'kwh' # Killowatt Hour
59
+ UNIT_LUX = 'lux' # Lux
60
+ UNIT_MAMP = 'ma' # Milliampere
61
+ UNIT_METER = 'm' # Meter
62
+ UNIT_MILLIMETER = 'mm' # Millimeter
63
+ UNIT_MILLIVOLTS = 'mv' # Millivolts
64
+ UNIT_OHM = 'ohm' # Ohm
65
+ UNIT_PASCAL = 'pa' # Pascal
66
+ UNIT_PERCENT = 'p' # Percent (%)
67
+ UNIT_PPM = 'ppm' # Parts per million
68
+ UNIT_RATIO = 'r' # Ratio
69
+ UNIT_ROTATION_PER_MINUTE = 'rpm' # Rotation per minute
70
+ UNIT_VOLTS = 'v' # Volts
71
+ UNIT_WATT = 'w' # Watts
32
72
33
73
# Topics
34
74
COMMAND_TOPIC = "cmd"
@@ -258,7 +298,7 @@ def hectoPascalWrite(self, channel, value):
258
298
"""
259
299
self .virtualWrite (channel , value , TYPE_BAROMETRIC_PRESSURE , UNIT_HECTOPASCAL )
260
300
261
- def accelWrite (self , channel , x , y , z ):
301
+ def accelWrite (self , channel , x = UNIT_UNDEFINED , y = UNIT_UNDEFINED , z = UNIT_UNDEFINED ):
262
302
"""Send an acceleration value list to Cayenne.
263
303
264
304
channel is the Cayenne channel to use.
@@ -267,9 +307,10 @@ def accelWrite(self, channel, x, y, z):
267
307
z is the acceleration on the Z-axis.
268
308
"""
269
309
value = [x , y , z ]
270
- self .virtualWrite (channel , repr (value ).replace (" " , "" ), TYPE_ACCELERATION , UNIT_GRAVITY )
310
+ value = '' .join (c for c in repr (value ) if c not in (" " , "'" ))
311
+ self .virtualWrite (channel , value , TYPE_ACCELERATION , UNIT_G )
271
312
272
- def gpsWrite (self , channel , latitude , longitude , altitude ):
313
+ def gpsWrite (self , channel , latitude = UNIT_UNDEFINED , longitude = UNIT_UNDEFINED , altitude = UNIT_UNDEFINED ):
273
314
"""Send a GPS value list to Cayenne.
274
315
275
316
channel is the Cayenne channel to use.
@@ -278,7 +319,8 @@ def gpsWrite(self, channel, latitude, longitude, altitude):
278
319
altitude is the altitude in meters.
279
320
"""
280
321
value = [latitude , longitude , altitude ]
281
- self .virtualWrite (channel , repr (value ).replace (" " , "" ), TYPE_GPS , UNIT_METER )
322
+ value = '' .join (c for c in repr (value ) if c not in (" " , "'" ))
323
+ self .virtualWrite (channel , value , TYPE_GPS , UNIT_METER )
282
324
283
325
def mqttPublish (self , topic , payload ):
284
326
"""Publish a payload to a topic
0 commit comments