From d473b9e1dc8c81dcdcf12612e8cb0686403ceeb8 Mon Sep 17 00:00:00 2001 From: Olivier Fauchon Date: Sun, 29 Jan 2023 20:11:47 +0100 Subject: [PATCH] lorawan/basic-demo: add debug logs at compile time with ldflags --- examples/lora/lorawan/basic-demo/README.md | 9 +++++++++ examples/lora/lorawan/basic-demo/main.go | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/lora/lorawan/basic-demo/README.md b/examples/lora/lorawan/basic-demo/README.md index 0191d66..866f9c8 100644 --- a/examples/lora/lorawan/basic-demo/README.md +++ b/examples/lora/lorawan/basic-demo/README.md @@ -33,3 +33,12 @@ tinygo flash -target pybadge -tags featherwing ./examples/lora/lorawan/basic-dem tinygo flash -target lorae5 ./examples/lora/lorawan/basic-demo ``` + +## Enable debugging + +You can also enable some debug logs with ldflags : + +``` +$ tinygo build -ldflags="-X 'main.debug=true'" -target=lorae5 +``` + diff --git a/examples/lora/lorawan/basic-demo/main.go b/examples/lora/lorawan/basic-demo/main.go index eed41fa..928799a 100644 --- a/examples/lora/lorawan/basic-demo/main.go +++ b/examples/lora/lorawan/basic-demo/main.go @@ -12,8 +12,9 @@ import ( "tinygo.org/x/drivers/lora/lorawan/region" ) +var debug string + const ( - debug = true LORAWAN_JOIN_TIMEOUT_SEC = 180 LORAWAN_RECONNECT_DELAY_SEC = 15 LORAWAN_UPLINK_DELAY_SEC = 60 @@ -88,7 +89,7 @@ func main() { // Configure AppEUI, DevEUI, APPKey setLorawanKeys() - if debug { + if debug != "" { println("main: Network joined") println("main: DevEui, " + otaa.GetDevEUI()) println("main: AppEui, " + otaa.GetAppEUI()) @@ -100,7 +101,7 @@ func main() { failMessage(err) } - if debug { + if debug != "" { println("main: NetID, " + otaa.GetNetID()) println("main: NwkSKey, " + session.GetNwkSKey()) println("main: AppSKey, " + session.GetAppSKey())