Hi,
just wanted to share my POC:
We're having a cleaning robot since years. It has built in scheduler and cleans based on that no matter if anyone is home or not.
I wanted to change that; I do have the status of precence in OpenHAB.
I have just created a simple mySensor node (based on a light switch) which sends 3 different commands to roomba:
clean
dock
stop
In openHAB it is just defined as a light switch and I can build up a schedule and if someone is home, it delays the start of cleaning until all are gone.
ToDo:
See if I can fit the parts inside of the cleaning robot but for POC I am happy
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
#include <MySensors.h>
#include <SoftwareSerial.h>
#define RELAY_1 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 2 // Total number of attached relays
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
int rxPin = 3;
int txPin = 4;
int ledPin = 13;
SoftwareSerial Roomba(rxPin, txPin);
#define bumpright (sensorbytes[0] & 0x01)
#define bumpleft (sensorbytes[0] & 0x02)
void setup() {
pinMode(ledPin, OUTPUT); // sets the pins as output
Serial.begin(115200);
Roomba.begin(115200);
digitalWrite(ledPin, HIGH); // say we're alive
Serial.println ("Sending start command...");
delay (1000);
// set up ROI to receive commands
Roomba.write(128); // START
delay(150);
Serial.println ("Sending Safe Mode command...");
delay (1000);
Roomba.write(131); // CONTROL
delay(150);
digitalWrite(ledPin, LOW); // say we've finished setup
Serial.println ("Ready to go!");
delay (5000);
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Roomba", "1.0");
for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_BINARY);
}
}
void loop() {
}
void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type == V_LIGHT) {
int mySensor = message.sensor;
int myComand = message.getBool();
//Serial.print(message.sensor-1+RELAY_1);
if (mySensor == 0) {
if (myComand == 1) {
Serial.println("Clean");
clean();
}
else {
Serial.println("Stopp1");
halt();
}
}
if (mySensor == 1) {
if (myComand == 1) {
Serial.println("dock");
dock();
}
else {
Serial.println("Stopp2");
halt();
}
}
}
}
void halt() {
;
Roomba.write(131); // SAFE
byte j = 0x00;
Roomba.write(137);
Roomba.write(j);
Roomba.write(j);
Roomba.write(j);
Roomba.write(j);
}
void dock() {
delay(1000);
Roomba.write(143);
}
void clean() {
delay(1000);
Roomba.write(135);
}
Cheers,
SJ