Skip to content

Commit

Permalink
mod. messages and wait_for_server() in switchbot_ros_client.py to set…
Browse files Browse the repository at this point in the history
… timeout.
  • Loading branch information
y-yosuke committed Apr 16, 2024
1 parent c567159 commit 261c360
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion switchbot_ros/msg/Bot.msg
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
string DEVICEMODE_PRESS = "pressMode"
string DEVICEMODE_SWITCH = "switchMode"
string DEVICEMODE_CUSTOMIZE = "customizeMode"

Header header # timestamp

float64 battery # the current battery level, 0-100

string power # ON/OFF state
bool power # ON/OFF state True/False
string device_mode # pressMode, switchMode, or customizeMode
6 changes: 4 additions & 2 deletions switchbot_ros/msg/StripLight.msg
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Header header # timestamp

string power # ON/OFF state
string color # the color value, RGB "255:255:255"
bool power # ON/OFF state True/False

int64 brightness # the brightness value, range from 1 to 100
int64 color_r # Red color value 0-255
int64 color_g # Green color value 0-255
int64 color_b # Blue color value 0-255
16 changes: 13 additions & 3 deletions switchbot_ros/scripts/switchbot_status_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,24 @@ def spin(self):
msg = Bot()
msg.header.stamp = time
msg.battery = status['battery']
msg.power = status['power']
if status['power'] == 'on':
msg.power = True
else:
msg.power = False
msg.device_mode = status['deviceMode']
elif self.msg_class == StripLight:
msg = StripLight()
msg.header.stamp = time
msg.power = status['power']
msg.color = status['color']
if status['power'] == 'on':
msg.power = True
else:
msg.power = False
msg.brightness = status['brightness']
rgb_string = status['color']
r, g, b = map(int, rgb_string.split(':'))
msg.color_r = r
msg.color_g = g
msg.color_b = b
else:
return

Expand Down
7 changes: 4 additions & 3 deletions switchbot_ros/src/switchbot_ros/switchbot_ros_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ class SwitchBotROSClient(object):

def __init__(self,
actionname='switchbot_ros/switch',
topicname='switchbot_ros/devices'):
topicname='switchbot_ros/devices',
timeout=5):

self.actionname = actionname
self.topicname = topicname
self.action_client = actionlib.SimpleActionClient(
actionname,
SwitchBotCommandAction
)
rospy.loginfo("Waiting for action server to start.")
self.action_client.wait_for_server()
rospy.loginfo("Waiting " + str(timeout) + "[sec] for action server to start .")
self.action_client.wait_for_server(timeout=rospy.Duration(timeout,0))

def get_devices(self, timeout=None):

Expand Down

0 comments on commit 261c360

Please sign in to comment.