Here is how I did it with Node Red (which I already had running on a Raspberry Pi server)
http in -> Process Geofence Function -> http response
|
|->CheckHomeStatus and PrepareURL function -> http request -> debug (optional)
Here's the http in: Method: GET URL: /geofence
Here's Process Geofence:
const phone = msg.req.query.phone;
const fence = msg.req.query.fence;
if (phone && fence) {
const isEntering = fence.toLowerCase() === 'entering';
const isExiting = fence.toLowerCase() === 'exiting';
if (isEntering || isExiting) {
const atHome = isEntering;
flow.set(phone, atHome);
msg.payload = {
status: 'success',
message: `${phone} is ${fence} the geofence`,
value: atHome
};
} else {
msg.payload = {
status: 'error',
message: 'Invalid fence value. Must be "entering" or "exiting".'
};
}
} else {
msg.payload = {
status: 'error',
message: 'Missing phone or fence parameter'
};
}
return msg;
http response is just Status Code: 200
CheckHomeStatus and PrepareURL function is:
function checkHomeStatusAndPrepareURL() {
const jillAtHome = flow.get('Jill') || false;
const peteAtHome = flow.get('Pete') || false;
let schedule;
if (!jillAtHome && !peteAtHome) {
schedule = 'Away';
} else {
schedule = 'Day_Night';
}
const baseUrl = 'http://10.123.123.123:81/admin';
const params = `schedule=${encodeURIComponent(schedule)}&lock=2&user=USERNAME&pw=PASSWORD3`;
msg.url = `${baseUrl}?${params}`;
return msg;
}
return checkHomeStatusAndPrepareURL();
and finally, the http request... Method: GET and ***LEAVE THE URL BLANK*** (that last part may not be obvious) Payload: ignore.
Then the messages that EgiGeoFence sends would look like these, for example:
http://10.222.222.222:1880/geofence?phone=Pete&fence=enteringhttp://10.222.222.222:1880/geofence?phone=Pete&fence=exitinghttp://10.222.222.222:1880/geofence?phone=Jill&fence=enteringhttp://10.222.222.222:1880/geofence?phone=Jill&fence=exiting