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
-
6
- import time
7
1
import paho .mqtt .client as mqtt
2
+ import time
8
3
from cayenne import __version__
9
- from cayenne .datatypes import *
4
+
5
+ # Data types
6
+ TYPE_BAROMETRIC_PRESSURE = "bp" # Barometric pressure
7
+ TYPE_BATTERY = "batt" # Battery
8
+ TYPE_LUMINOSITY = "lum" # Luminosity
9
+ TYPE_PROXIMITY = "prox" # Proximity
10
+ TYPE_RELATIVE_HUMIDITY = "rel_hum" # Relative Humidity
11
+ TYPE_TEMPERATURE = "temp" # Temperature
12
+ TYPE_VOLTAGE = "voltage" # Voltage
13
+
14
+ # Unit types
15
+ UNIT_UNDEFINED = "null"
16
+ UNIT_PASCAL = "pa" # Pascal
17
+ UNIT_HECTOPASCAL = "hpa" # Hectopascal
18
+ UNIT_PERCENT = "p" # % (0 to 100)
19
+ UNIT_RATIO = "r" # Ratio
20
+ UNIT_VOLTS = "v" # Volts
21
+ UNIT_LUX = "lux" # Lux
22
+ UNIT_CENTIMETER = "cm" # Centimeter
23
+ UNIT_METER = "m" # Meter
24
+ UNIT_DIGITAL = "d" # Digital (0/1)
25
+ UNIT_FAHRENHEIT = "f" # Fahrenheit
26
+ UNIT_CELSIUS = "c" # Celsius
27
+ UNIT_KELVIN = "k" # Kelvin
28
+ UNIT_MILLIVOLTS = "mv" # Millivolts
10
29
11
30
# Topics
12
31
COMMAND_TOPIC = "cmd"
@@ -33,7 +52,7 @@ def on_connect(client, cayenne, flags, rc):
33
52
# reconnect then subscriptions will be renewed.
34
53
cayenne .connected = True
35
54
cayenne .reconnect = False
36
- command_topic = cayenne .getCommandTopic ()
55
+ command_topic = cayenne .getCommandTopic ();
37
56
print ("SUB %s\n " % command_topic )
38
57
client .subscribe (command_topic )
39
58
cayenne .mqttPublish ("%s/sys/model" % cayenne .rootTopic , "Python" )
@@ -236,30 +255,6 @@ def hectoPascalWrite(self, channel, value):
236
255
"""
237
256
self .virtualWrite (channel , value , TYPE_BAROMETRIC_PRESSURE , UNIT_HECTOPASCAL )
238
257
239
- def accelWrite (self , channel , x = UNIT_UNDEFINED , y = UNIT_UNDEFINED , z = UNIT_UNDEFINED ):
240
- """Send an acceleration value list to Cayenne.
241
-
242
- channel is the Cayenne channel to use.
243
- x is the acceleration on the X-axis.
244
- y is the acceleration on the Y-axis.
245
- z is the acceleration on the Z-axis.
246
- """
247
- value = [x , y , z ]
248
- value = '' .join (c for c in repr (value ) if c not in (" " , "'" ))
249
- self .virtualWrite (channel , value , TYPE_ACCELERATION , UNIT_G )
250
-
251
- def gpsWrite (self , channel , latitude = UNIT_UNDEFINED , longitude = UNIT_UNDEFINED , altitude = UNIT_UNDEFINED ):
252
- """Send a GPS value list to Cayenne.
253
-
254
- channel is the Cayenne channel to use.
255
- latitude is the latitude in degrees.
256
- longitude is the longitude in degrees.
257
- altitude is the altitude in meters.
258
- """
259
- value = [latitude , longitude , altitude ]
260
- value = '' .join (c for c in repr (value ) if c not in (" " , "'" ))
261
- self .virtualWrite (channel , value , TYPE_GPS , UNIT_METER )
262
-
263
258
def mqttPublish (self , topic , payload ):
264
259
"""Publish a payload to a topic
265
260
0 commit comments