Skip to content

Commit

Permalink
add codes for publishing switchbot CO2 meter status.
Browse files Browse the repository at this point in the history
  • Loading branch information
y-yosuke committed Nov 18, 2024
1 parent fb32bec commit 73b6eba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions switchbot_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_message_files(
Device.msg
DeviceArray.msg
Meter.msg
MeterProCO2.msg
PlugMini.msg
Hub2.msg
Bot.msg
Expand Down
7 changes: 7 additions & 0 deletions switchbot_ros/msg/MeterProCO2.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Header header # timestamp

float64 temperature # temperature in celsius
float64 humidity # humidity percentage
float64 battery # the current battery level, 0-100

int64 co2ppm # CO2 ppm value, 0-9999
11 changes: 10 additions & 1 deletion switchbot_ros/scripts/switchbot_status_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import rospy
from switchbot_ros.switchbot import SwitchBotAPIClient
from switchbot_ros.switchbot import DeviceError, SwitchBotAPIError
from switchbot_ros.msg import Meter, PlugMini, Hub2, Bot, StripLight
from switchbot_ros.msg import Meter, PlugMini, Hub2, Bot, StripLight, MeterProCO2


class SwitchBotStatusPublisher:
Expand Down Expand Up @@ -84,6 +84,8 @@ def __init__(self):
self.msg_class = Bot
elif self.device_type == 'Strip Light':
self.msg_class = StripLight
elif self.device_type == 'MeterPro(CO2)':
self.msg_class = MeterProCO2
else:
rospy.logerr('No publisher process for "' + self.device_type + '" in switchbot_status_publisher.py')
return
Expand Down Expand Up @@ -158,6 +160,13 @@ def spin(self):
msg.color_r = r
msg.color_g = g
msg.color_b = b
elif self.msg_class == MeterProCO2:
msg = MeterProCO2()
msg.header.stamp = time
msg.temperature = status['temperature']
msg.humidity = status['humidity']
msg.battery = status['battery']
msg.co2ppm = status['CO2']
else:
return

Expand Down

0 comments on commit 73b6eba

Please sign in to comment.