// GetAppEUI returns the AppEUI that must be set in the command options or config func GetAppEUI(ctx log.Interface) types.AppEUI { appEUIString := viper.GetString("app-eui") if appEUIString == "" { appData := readData(appFilename) eui, ok := appData[euiKey].(string) if !ok { ctx.Fatal("Invalid AppEUI in config file") } appEUIString = eui } if appEUIString == "" { ctx.Fatal("Missing AppEUI. You should select an application to use with \"ttnctl applications select\"") } eui, err := types.ParseAppEUI(appEUIString) if err != nil { ctx.WithError(err).Fatal("Invalid AppEUI") } return eui }
INFO Added Application INFO Selected Current Application `, Run: func(cmd *cobra.Command, args []string) { if len(args) != 2 { cmd.UsageFunc()(cmd) return } var euis []types.AppEUI euiStrings, err := cmd.Flags().GetStringSlice("app-eui") if err != nil { ctx.WithError(err).Fatal("Could not read app-eui options") } for _, euiString := range euiStrings { eui, err := types.ParseAppEUI(euiString) if err != nil { ctx.WithError(err).Fatal("Could not read app-eui") } euis = append(euis, eui) } account := util.GetAccount(ctx) app, err := account.CreateApplication(args[0], args[1], euis) if err != nil { ctx.WithError(err).Fatal("Could not add application") } util.ForceRefreshToken(ctx)
dev, err := manager.GetDevice(appID, devID) if err != nil { ctx.WithError(err).Fatal("Could not get existing device.") } // Do all updates if in, err := cmd.Flags().GetString("app-eui"); err == nil && in != "" { ctx.Warn("Manually changing the AppEUI of a device might break routing for this device") if override, _ := cmd.Flags().GetBool("override"); !override { ctx.Warnf("Use the --override flag if you're really sure you want to do this") os.Exit(0) } appEUI, err := types.ParseAppEUI(in) if err != nil { ctx.Fatalf("Invalid AppEUI: %s", err) } dev.GetLorawanDevice().AppEui = &appEUI } if in, err := cmd.Flags().GetString("dev-eui"); err == nil && in != "" { ctx.Warn("Manually changing the DevEUI of a device might break routing for this device") if override, _ := cmd.Flags().GetBool("override"); !override { ctx.Warnf("Use the --override flag if you're really sure you want to do this") os.Exit(0) } devEUI, err := types.ParseDevEUI(in)
"github.com/spf13/cobra" "github.com/spf13/viper" ) var joinCmd = &cobra.Command{ Hidden: true, Use: "join [AppEUI] [DevEUI] [AppKey] [DevNonce]", Short: "Simulate an join message to the network", Long: `ttnctl join simulates an join message to the network`, Run: func(cmd *cobra.Command, args []string) { if len(args) != 4 { cmd.UsageFunc()(cmd) return } appEUI, err := types.ParseAppEUI(args[0]) if err != nil { ctx.WithError(err).Fatal("Could not parse AppEUI") } devEUI, err := types.ParseDevEUI(args[1]) if err != nil { ctx.WithError(err).Fatal("Could not parse DevEUI") } appKey, err := types.ParseAppKey(args[2]) if err != nil { ctx.WithError(err).Fatal("Could not parse AppKey") } devNonceSlice, err := types.ParseHEX(args[3], 2)