Skip to content

Instantly share code, notes, and snippets.

@RamonBell
Created April 9, 2023 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RamonBell/9f7d29032b0ee989ce7b0adb579f2bdc to your computer and use it in GitHub Desktop.
Save RamonBell/9f7d29032b0ee989ce7b0adb579f2bdc to your computer and use it in GitHub Desktop.
google to mqtt post
function postCalendarEventsToMQTT() {
// Replace the values in these variables with your own information
const CALENDAR_ID = r########@gmail.com;
const MQTT_BROKER_URL = mqtt://192.168.1.198:1883;
const MQTT_TOPIC = main_calendar;
// Set up the MQTT client
const mqttClient = MQTT.connect(MQTT_BROKER_URL);
// Get the calendar events
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
const events = calendar.getEvents(new Date(), new Date(new Date().getTime() + (24 * 60 * 60 * 1000))); // Get events for the next 24 hours
// Post each event to MQTT
events.forEach(function(event) {
const eventData = {
'title': event.getTitle(),
'start': event.getStartTime().toISOString(),
'end': event.getEndTime().toISOString()
};
mqttClient.publish(MQTT_TOPIC, JSON.stringify(eventData));
});
// Disconnect the MQTT client
mqttClient.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment