diff --git a/setup-node/main.go b/setup-node/main.go index 18c83f7..ecc4338 100644 --- a/setup-node/main.go +++ b/setup-node/main.go @@ -10,22 +10,28 @@ import ( "time" ) +// read serial buffer +func readUntilEmpty(p *serial.Port) { + p.Flush() + time.Sleep(100 * time.Millisecond) + ignorebuf := make([]byte, 1024) + p.Read(ignorebuf) +} + // returns last line of output func sendCommand(p *serial.Port, command string) string { fmt.Printf("%s\n", command) var first_line string = "" p.Flush() - time.Sleep(300 * time.Millisecond) - ignorebuf := make([]byte, 1024) - p.Read(ignorebuf) + time.Sleep(500 * time.Millisecond) + readUntilEmpty(p) _, err := p.Write([]byte(command + "\n")) if err != nil { log.Fatal(err) } buf := make([]byte, 1024) - time.Sleep(300 * time.Millisecond) - + time.Sleep(500 * time.Millisecond) n, _ := p.Read(buf) if n > 0 { lines := strings.Split(string(buf[:n]), "\n") @@ -141,6 +147,7 @@ func main() { defer f.Close() sendCommand(s, "AT") + sendCommand(s, "ATNJM=0") devEui := getDevEui(s) FWVersion := getFWVersion(s) if devEui != "" { @@ -150,6 +157,7 @@ func main() { sendCommand(s, "AT+APPKEY="+appkey) sendCommand(s, "AT+FDR") sendCommand(s, "AT+LON=0") + sendCommand(s, "ATNJM=1") sendCommand(s, "ATZ") logline := strings.ToUpper(fmt.Sprintf("%s: %s %s %s %s\n", time.Now().In(location).Format("02.01.2006 15:04"), strings.ReplaceAll(devEui, " ", ""), strings.ReplaceAll(appEui, " ", ""), strings.ReplaceAll(appkey, " ", ""), FWVersion)) if _, err := f.WriteString(logline); err != nil { diff --git a/setup-node/setup-node.log b/setup-node/setup-node.log index b364154..4f68e74 100644 --- a/setup-node/setup-node.log +++ b/setup-node/setup-node.log @@ -4,5 +4,18 @@ 14.05.2021 16:52: A8404100018193D7 A840413510351035 80407114A08019D30090781148A01D43 V1.6.5 EU868 14.05.2021 20:26: A8404100018193D7 A840413510351035 80407114A08019D30090781148A01D43 V1.6.5 EU868 14.05.2021 20:32: A8404100018193F3 A840413510351035 80403114A08019F30090381148A01F43 V1.6.5 EU868 -02.06.2021 19:44: A8404100018193DE A840413510351035 8040E114A08019D30090E81148A01D43 02.06.2021 19:49: A8404100018193DE A840413510351035 8040E114A08019D30090E81148A01D43 V1.6.5 EU868 +22.06.2021 16:30: A840410001819382 A840413510351035 80402114A08019830090281148A01843 V1.6.5 EU868 +22.06.2021 16:50: A8404100018193D1 A840413510351035 80401114A08019D30090181148A01D43 V1.6.5 EU868 +22.06.2021 16:56: A8404100018193B4 A840413510351035 80404114A08019B30090481148A01B43 V1.6.5 EU868 +22.06.2021 17:06: A840410001819388 A840413510351035 80408114A08019830090881148A01843 V1.6.5 EU868 +22.06.2021 17:11: A8404100018193C0 A840413510351035 80400114A08019C30090081148A01C43 V1.6.5 EU868 +22.06.2021 17:13: A8404100018193DA A840413510351035 8040A114A08019D30090A81148A01D43 V1.6.5 EU868 +22.06.2021 17:14: A8404100018193AD A840413510351035 8040D114A08019A30090D81148A01A43 V1.6.5 EU868 +22.06.2021 17:16: A8404100018193CA A840413510351035 8040A114A08019C30090A81148A01C43 V1.6.5 EU868 +22.06.2021 17:18: A84041000181937A A840413510351035 8040A114A08019730090A81148A01743 V1.6.5 EU868 +22.06.2021 17:20: A8404100018193B9 A840413510351035 80409114A08019B30090981148A01B43 V1.6.5 EU868 +22.06.2021 17:22: A8404100018193C3 A840413510351035 80403114A08019C30090381148A01C43 V1.6.5 EU868 +22.06.2021 17:31: A8404100018193AE A840413510351035 8040E114A08019A30090E81148A01A43 V1.6.5 EU868 +22.06.2021 17:51: A8404100018193B3 A840413510351035 80403114A08019B30090381148A01B43 V1.6.5 EU868 +22.06.2021 17:56: A84041000181938D A840413510351035 8040D114A08019830090D81148A01843 V1.6.5 EU868