Skip to content

Commit a27d7ae

Browse files
authored
Revert "Add new data types and units."
1 parent 9a2ef93 commit a27d7ae

File tree

5 files changed

+36
-114
lines changed

5 files changed

+36
-114
lines changed

cayenne/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.2a1"
1+
__version__ = "1.0.1"

cayenne/client.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
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
71
import paho.mqtt.client as mqtt
2+
import time
83
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
1029

1130
# Topics
1231
COMMAND_TOPIC = "cmd"
@@ -33,7 +52,7 @@ def on_connect(client, cayenne, flags, rc):
3352
# reconnect then subscriptions will be renewed.
3453
cayenne.connected = True
3554
cayenne.reconnect = False
36-
command_topic = cayenne.getCommandTopic()
55+
command_topic = cayenne.getCommandTopic();
3756
print("SUB %s\n" % command_topic)
3857
client.subscribe(command_topic)
3958
cayenne.mqttPublish("%s/sys/model" % cayenne.rootTopic, "Python")
@@ -236,30 +255,6 @@ def hectoPascalWrite(self, channel, value):
236255
"""
237256
self.virtualWrite(channel, value, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL)
238257

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-
263258
def mqttPublish(self, topic, payload):
264259
"""Publish a payload to a topic
265260

cayenne/datatypes.py

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from cayenne import client, datatypes
2+
import cayenne.client
33
import time
44

55
# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
@@ -13,20 +13,19 @@ def on_message(message):
1313
print("message received: " + str(message))
1414
# If there is an error processing the message return an error string, otherwise return nothing.
1515

16-
cayenne_client = client.CayenneMQTTClient()
17-
cayenne_client.on_message = on_message
18-
cayenne_client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
16+
client = cayenne.client.CayenneMQTTClient()
17+
client.on_message = on_message
18+
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
1919

2020
i=0
2121
timestamp = 0
2222

2323
while True:
24-
cayenne_client.loop()
24+
client.loop()
2525

2626
if (time.time() > timestamp + 10):
27-
cayenne_client.celsiusWrite(1, i)
28-
cayenne_client.luxWrite(2, i*10)
29-
cayenne_client.hectoPascalWrite(3, i+800)
30-
cayenne_client.virtualWrite(4, i%2, datatypes.TYPE_DIGITAL_SENSOR, datatypes.UNIT_DIGITAL)
27+
client.celsiusWrite(1, i)
28+
client.luxWrite(2, i*10)
29+
client.hectoPascalWrite(3, i+800)
3130
timestamp = time.time()
3231
i = i+1

tests/Test-01-TestClient.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def on_message(message):
4343
client.luxWrite(4, 4)
4444
client.pascalWrite(5, 5)
4545
client.hectoPascalWrite(6, 6)
46-
client.accelWrite(7, 7.01, 7.02, -7.03)
47-
client.gpsWrite(8, 27.986065, 86.922623, 8848)
4846

4947
print("Test receiving commands")
5048
client.mqttPublish(client.rootTopic + '/cmd/10', 'senderror,0')

0 commit comments

Comments
 (0)