|
| 1 | +""" |
| 2 | +This module contains the main agent client for connecting to the Cayenne server. The client connects |
| 3 | +to server, sends data to the server and handles commands from the server. |
| 4 | +""" |
| 5 | + |
1 | 6 | import time
|
2 | 7 | import paho.mqtt.client as mqtt
|
3 | 8 | from cayenne import __version__
|
4 |
| - |
5 |
| - |
6 |
| -# Data types |
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 |
38 |
| - |
39 |
| -# Unit types |
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 |
| 9 | +from cayenne.datatypes import * |
72 | 10 |
|
73 | 11 | # Topics
|
74 | 12 | COMMAND_TOPIC = "cmd"
|
|
0 commit comments