Skip to content

Instantly share code, notes, and snippets.

@BK1031
Last active July 11, 2024 11:26
Show Gist options
  • Save BK1031/7c56ce7440663b11ecf463f6a480fb97 to your computer and use it in GitHub Desktop.
Save BK1031/7c56ce7440663b11ecf463f6a480fb97 to your computer and use it in GitHub Desktop.
racecar_analytics create rows in subscription handlers
func SubscribeECU() {
Client.Subscribe("ingest/ecu", 0, func(client mqtt.Client, msg mqtt.Message) {
ecu := ECUFromBytes(msg.Payload())
// ------ add this ------
ecu, err := CreateECU(ecu)
if err != nil {
fmt.Printf("failed to create ecu: %v", err)
}
// ----------------------
fmt.Printf("[MQ] Received ecu message: %v\n", ecu)
})
}
func SubscribeBattery() {
Client.Subscribe("ingest/battery", 0, func(client mqtt.Client, msg mqtt.Message) {
battery := BatteryFromBytes(msg.Payload())
// ------ add this ------
battery, err := CreateBattery(battery)
if err != nil {
fmt.Printf("failed to create battery: %v", err)
}
// ----------------------
fmt.Printf("[MQ] Received battery message: %v\n", battery)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment