func main() {
	say.SetLevelWithConfName("info")

	configFile, config, err := conf.FromArgs()
	switch {
	case err != nil:
		say.Fatalf("Cannot read configuration in `%s` with error: %s", configFile, err.Error())
	case configFile == "":
		say.Infof("You should specify configuration file. Starting with test configuration: %+v", config)
	default:
		say.Infof("Starting DeviceHive gateway with configuration in '%s': %+v", configFile, config)
	}

	say.SetLevelWithConfName(config.LoggingLevel)

	bus, err := dbus.SystemBus()
	if err != nil {
		say.Infof("Cannot get system bus with error: %s", err.Error())
		say.Infof("Trying to use session bus for testing purposes...")
		if bus, err = dbus.SessionBus(); err != nil {
			say.Fatalf("Cannot get session bus with error: %s\n", err.Error())
			return
		}
	}

	reply, err := bus.RequestName(DBusConnName, dbus.NameFlagDoNotQueue)
	switch {
	case err != nil:
		say.Fatalf("Cannot request name '%s' with error: %s\n", DBusConnName, err.Error())
	case reply != dbus.RequestNameReplyPrimaryOwner:
		say.Fatalf("The name '%s' already taken.", DBusConnName)
	}

	if config.DeviceNotificationReceive == conf.DeviceNotificationReceiveByWS {
		say.Infof("Starting as websocket...")
		wsImplementation(bus, config)
		return
	}

	if config.DeviceNotificationReceive == conf.DeviceNotificationReceiveByREST {
		say.Infof("Starting as rest...")
		restImplementation(bus, config)
		return
	}

}
func main() {
	say.Level = say.DEBUG

	f, c, err := conf.FromArgs()
	if err != nil {
		say.Infof("Load conf err: %s", err.Error())
		return
	}

	say.Infof("Conf(%s): %+v", f, c)

	err = rest.DeviceRegisterEasy(c.URL, c.DeviceID, c.AccessKey, c.DeviceName)

	if err != nil {
		say.Infof("Error: %s", err.Error())
	} else {
		say.Infof("Ok")
	}
}
func main() {
	name := "TestRestNotification"
	parameters := map[string]interface{}{"key1": "value1"}

	f, c, err := conf.FromArgs()
	if err != nil {
		say.Infof("Load conf err: %s", err.Error())
		return
	}

	say.Infof("Conf(%s): %+v", f, c)

	dnir, err := rest.DeviceNotificationInsert(c.URL, c.DeviceID, c.AccessKey, name, parameters)

	if err != nil {
		say.Infof("Error: %s", err.Error())
	} else {
		say.Infof("Ok: %+v", dnir)
	}
}
func main() {
	var id uint32 = 782346
	status := "UpdateCommandTestStatus"
	result := "UpdateCommandTestResult"

	f, c, err := conf.FromArgs()
	if err != nil {
		say.Infof("Load conf err: %s", err.Error())
		return
	}

	say.Infof("Conf(%s): %+v", f, c)

	err = rest.DeviceCmdUpdate(c.URL, c.DeviceID, c.AccessKey, id, status, result)

	if err != nil {
		say.Infof("Error: %s", err.Error())
	} else {
		say.Infof("ok")
	}
}
Example #5
0
func main() {
	configFile, config, err := conf.FromArgs()
	switch {
	case err != nil:
		log.Fatalf("Failed to read %q configuration (%s)", configFile, err)
	case configFile == "":
		log.Warnf("No configuration file provided!")
		log.Infof("Test configuration is used: %+v", config)
	default:
		log.Infof("Starting DeviceHive with %q configuration: %+v", configFile, config)
	}

	log.SetLevelByName(config.LoggingLevel)

	bus, err := dbus.SystemBus()
	if err != nil {
		log.Warnf("Cannot get system bus (error: %s)", err)
		log.Infof("Trying to use session bus for testing purposes...")
		if bus, err = dbus.SessionBus(); err != nil {
			log.Fatalf("Cannot get session bus (error: %s)", err)
			return
		}
	}

	reply, err := bus.RequestName(DBusConnName, dbus.NameFlagDoNotQueue)
	switch {
	case err != nil:
		log.Fatalf("Cannot request name %q (error: %s)", DBusConnName, err)
	case reply != dbus.RequestNameReplyPrimaryOwner:
		log.Fatalf("The name %q already taken", DBusConnName)
	}

	s, err := devicehive.NewService(config.URL, config.AccessKey)
	if err != nil {
		log.Fatalf("Failed to create DeviceHive service (error: %s)", err)
	}

	log.Infof("Starting %v", s)
	mainLoop(bus, s, config)
}