#! #keepAttributeError: 'Float32' object has no attribute 'humidity' [ERROR] [1604594380.746952]: bad callback: <function callback at 0x7f72bc562488> Traceback (most recent call last)
Code below:
#!/usr/bin/env python
import time
import rospy
from std_msgs.msg import Float32
from std_msgs.msg import Int32
def callback(humidity):
motor(humidity)
def motor(humidity):
pub=rospy.Publisher('Servo', Int32, queue_size=10) #rospy.Publisher(Topic name, Type, queue_size )
#rospy.init_node('motor',anonymous=True) #rospy.init_node(Node name,anonymous=True)
rate=rospy.Rate(10) #10Hz
if humidity.humidity > 50:
pub.publish(180)
rospy.loginfo(humidity_value.humidity)
else:
pub.publish(0)
rospy.loginfo(humidity_value.humidity)
rate.sleep()
def listener():
rospy.init_node('listener', anonymous=True) #anonymus let us have many node named the same way running simultaneously
rospy.Subscriber('humidity', Float32,callback) #Callback name of the function you need to call when you get data
rospy.spin() #keeps the program running until the node is stopped
if __name__=='__main__':
listener()