Skip to content

Commit 1ff0fa4

Browse files
authored
Merge pull request #39 from digidotcom/BugFix/negative-temperature
samples: treat atcmd('TP') as signed 16-bit value
2 parents 3986ca2 + 5060198 commit 1ff0fa4

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

samples/bluetooth/eddystone_advertise/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def advertise_payload_for(payload, time_sec, interval_usec):
6969
while True:
7070
time_alive = time.ticks_diff(time.ticks_ms(), start_time) / 1000
7171
beacon_temperature = xbee.atcmd('TP')
72+
# convert unsigned 16-bit value to signed beacon_temperature
73+
if beacon_temperature > 0x7FFF:
74+
beacon_temperature = beacon_temperature - 0x10000
7275
# If the %V command is supported (XBee 3 LTE-M) the following line can be uncommented.
7376
# battery_voltage = xbee.atcmd('%V') / 1000
7477

samples/filesystem/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
stopped = False
5353
while not stopped:
5454
temperature = xbee.atcmd("TP")
55+
# convert unsigned 16-bit value to signed temperature
56+
if temperature > 0x7FFF:
57+
temperature = temperature - 0x10000
5558
# Write the current temperature in the log file.
5659
dummy = log.write("Current temperature: %.1F C (%.1F F)\n" % (temperature, temperature * 9.0 / 5.0 + 32.0))
5760
# Wait 1 second until the next reading.

samples/remote_manager/drm_http_requests/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ def upload_datapoint(stream_id, data):
9090

9191
# Start uploading temperature samples.
9292
while True:
93-
temperature = int(xbee.atcmd('TP') * 9.0 / 5.0 + 32.0)
93+
temperature = xbee.atcmd("TP")
94+
# convert unsigned 16-bit value to signed temperature
95+
if temperature > 0x7FFF:
96+
temperature = temperature - 0x10000
97+
temperature = int(temperature * 9.0 / 5.0 + 32.0)
9498
print("- Uploading datapoint to datastream '%s'... " % STREAM_ID, end="")
9599
if upload_datapoint(STREAM_ID, temperature):
96100
print("[OK]")

samples/remote_manager/send_data_points/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636

3737
# Read the temperature every 5 seconds during a minute.
3838
for i in range(12):
39-
temperature = int(xbee.atcmd('TP') * 9.0 / 5.0 + 32.0)
39+
temperature = xbee.atcmd("TP")
40+
# convert unsigned 16-bit value to signed temperature
41+
if temperature > 0x7FFF:
42+
temperature = temperature - 0x10000
43+
temperature = int(temperature * 9.0 / 5.0 + 32.0)
4044
data.add(DATAPOINT_TEMPERATURE, temperature)
4145
time.sleep(5)
4246

samples/xbee/at_commands/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
# Read the module's temperature.
3737
temperature = xbee.atcmd("TP")
38+
# convert unsigned 16-bit value to signed temperature
39+
if temperature > 0x7FFF:
40+
temperature = temperature - 0x10000
3841
print("The XBee is %.1F C (%.1F F)" % (temperature, temperature * 9.0 / 5.0 + 32.0))
3942

4043
# Configure the module's node identifier and read it.

0 commit comments

Comments
 (0)