Close

Logs and maps (part 1)

A project log for Old Roomba, new tricks

Add mapping & MQTT-interfacing with ESP8266 and an IMU

simon-jansenSimon Jansen 08/28/2022 at 19:430 Comments

Always fun when your wild ideas seem quite possible

I'm doing some experimenting with python on the Pi to log positioning info. I edited the sketch to output a stream of calculated pose data to construct a map with. And a stream with raw positional sensordata to do postprocessing, analysis and hopefully improve the accuracy of the system. 

The python daemon will listen to these streams and make separate log-files. These files are opened/created and closed/saved on the start and end of a cleaning cycle. 

After a cleaning cycle is done, the pose-log will be used to create a map-image. This image can be sent with MQTT and will display in Home Assistant. This seems to work brilliantly when testing with a dummy image:

I'm very curious if someone has a better way of getting something like a map in Home Assistant.

The MQTT autodiscovery and setup for the map and topics to subscribe to:

#Roomba device info for Home Assistant autoconfig
DeviceName = 'Roomba632'
DeviceID = '01'
DeviceManufacturer = 'iRobot'
DeviceModel = '632'

# MQTT autoconfig
device = {}
device['identifiers'] = DeviceName + "_" + DeviceID
device['name'] = DeviceName + "_" + DeviceID
device['manufacturer'] = DeviceManufacturer
#device['sw_version'] = ""
device['model'] = DeviceModel
# - Camera entity for maps
data = {}
data['name'] = "Map of last clean"
data['topic'] = MQTT_Config.HA_name + "/camera/" + DeviceName + "_" + DeviceID + "/map"
#data['availability_topic'] = MQTT_Config.HA_name + "/camera/" + DeviceName + "_" + DeviceID + "/available"
#data['payload_available'] = 'yes'
#data['payload_available'] = 'no'
data['unique_id'] = DeviceName + "_" + DeviceID + "_Map"
data['icon'] = "mdi:map-outline"
data['device'] = device
client.publish(MQTT_Config.HA_name + "/camera/" + DeviceName + "_" + DeviceID + "/config",json.dumps(data),0,True)
    
# MQTT subscribe to command topics to receive commands
# - Start clean cycle:
client.subscribe(MQTT_Config.HA_name + "/device_automation/" + DeviceName + "_" + DeviceID + "/event_DoneCleaning",0)
# - Event for ending of clean cylce:
client.subscribe(MQTT_Config.HA_name + "/button/" + DeviceName + "_" + DeviceID + "/set",0)
# - Positional data calculated on roomba:
client.subscribe(MQTT_Config.HA_name + "/device/roomba/pose",0)
# - Raw sensordata for postprocess calculation of position
client.subscribe(MQTT_Config.HA_name + "/device/roomba/raw",0)

I'm able to listen to the pose and raw topics and can also deconstruct the JSON message. It shouldn't be that hard to log to file and plot something of a map... to be continued

Discussions