Skip to content

Commit 73b6eba

Browse files
committed
add codes for publishing switchbot CO2 meter status.
1 parent fb32bec commit 73b6eba

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

switchbot_ros/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_message_files(
1515
Device.msg
1616
DeviceArray.msg
1717
Meter.msg
18+
MeterProCO2.msg
1819
PlugMini.msg
1920
Hub2.msg
2021
Bot.msg

switchbot_ros/msg/MeterProCO2.msg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Header header # timestamp
2+
3+
float64 temperature # temperature in celsius
4+
float64 humidity # humidity percentage
5+
float64 battery # the current battery level, 0-100
6+
7+
int64 co2ppm # CO2 ppm value, 0-9999

switchbot_ros/scripts/switchbot_status_publisher.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import rospy
66
from switchbot_ros.switchbot import SwitchBotAPIClient
77
from switchbot_ros.switchbot import DeviceError, SwitchBotAPIError
8-
from switchbot_ros.msg import Meter, PlugMini, Hub2, Bot, StripLight
8+
from switchbot_ros.msg import Meter, PlugMini, Hub2, Bot, StripLight, MeterProCO2
99

1010

1111
class SwitchBotStatusPublisher:
@@ -84,6 +84,8 @@ def __init__(self):
8484
self.msg_class = Bot
8585
elif self.device_type == 'Strip Light':
8686
self.msg_class = StripLight
87+
elif self.device_type == 'MeterPro(CO2)':
88+
self.msg_class = MeterProCO2
8789
else:
8890
rospy.logerr('No publisher process for "' + self.device_type + '" in switchbot_status_publisher.py')
8991
return
@@ -158,6 +160,13 @@ def spin(self):
158160
msg.color_r = r
159161
msg.color_g = g
160162
msg.color_b = b
163+
elif self.msg_class == MeterProCO2:
164+
msg = MeterProCO2()
165+
msg.header.stamp = time
166+
msg.temperature = status['temperature']
167+
msg.humidity = status['humidity']
168+
msg.battery = status['battery']
169+
msg.co2ppm = status['CO2']
161170
else:
162171
return
163172

0 commit comments

Comments
 (0)