Example #1
0
func main() {
	//Command line variables
	topic := flag.String("t", "home/#", "Enter the topic to subscribe to.")
	mqttServer := flag.String("s", ":1883", "Enter the IP and Port of the MQTT Broker. e.g. 127.0.0.1:1883")
	flag.Parse()

	mqttClient := mqttservices.NewClient(*mqttServer)

	chSub := mqttClient.Subscribe([]proto.TopicQos{{
		Topic: *topic,
		Qos:   proto.QosAtMostOnce,
	}})

	for m := range chSub {
		log.Printf("%s\t\t%s\n", m.TopicName, m.Payload)
	}
}
Example #2
0
func main() {
	//PWS - Personal Weather Station
	pws := wupws.New(*stationID, *password, *software, *calculateDewpoint)
	mqttClient := mqttservices.NewClient(*mqttServer)
	cache := sensorCache.New(*sensorExpire)

	//go routine to check if the data stored in the cache is expired
	go cache.MonitorExpiry(*checkCache)

	//go routine to capture readings into cache
	wg.Add(1)
	go cacheReadings(cache, mqttClient)

	//go routine to do the updates
	wg.Add(1)
	go pushUpdates(cache, *stationReportPeriod, pws)

	wg.Wait()

	log.Println("wuMQTTAgregate: Exiting")
}