Created
April 9, 2023 22:22
-
-
Save RamonBell/9f7d29032b0ee989ce7b0adb579f2bdc to your computer and use it in GitHub Desktop.
google to mqtt post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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