WISOL LSM110A RUNNING TINYGO IDE GOLANG - LoRaWAN
The purpose of this BLOG is to demonstrate how it is possible to program the WISOL LSM110A module (STM32WL55) with the TinyGo language, Breakout was used for LSM110A.
BETA BETA BETA BETA
A communication with LoRaWAN server ChirpStack and TTTN will be performed (OTAA, AU915), a Hello TinyGo #XX text will be sent every 60 seconds (FUP), the #XX is a counter.
Requires your knowledge of Go/TinyGo
Follow discussion at
What is TTN
The Network of Things (TTN) is an initiative initiated by Dutch civil society. The goal is to have LoRaWAN networks installed in every city in the world. By interconnecting these local networks, TTN wants to build a worldwide infrastructure to facilitate a public Internet of Things (IoT).
The best LoRaWAN provider.
TinyGO
TinyGo is a project to bring the Go programming language to microcontrollers and modern browsers by creating a new LLVM-based compiler.
You can compile and run TinyGo programs on many different microcontroller boards, such as the BBC micro:bit and the Arduino Uno.
TinyGo can also be used to produce WebAssembly (WASM) code, which is very compact in size.
Just want to see the code? Go to the Github repository at
TinyGo also supports many different devices such as accelerometers and magnetometers. Check out the Github repository at
https://github.com/tinygo-org/drivers for more information.
Attention:
c:\go\bin\go get tinygo.org/x/drivers
LoRaWAN
go.mod
module demo
go 1.19
require tinygo.org/x/drivers v0.23.0 // indirect
main.go
// Simple code for connecting to Lorawan network and uploading sample payload package main import ( "errors" "strconv" "time" "tinygo.org/x/drivers/examples/lora/lorawan/common" "tinygo.org/x/drivers/lora" "tinygo.org/x/drivers/lora/lorawan" "tinygo.org/x/drivers/lora/lorawan/region" ) var debug string const ( LORAWAN_JOIN_TIMEOUT_SEC = 180 LORAWAN_RECONNECT_DELAY_SEC = 15 LORAWAN_UPLINK_DELAY_SEC = 60 ) var ( radio lora.Radio session *lorawan.Session otaa *lorawan.Otaa ) func loraConnect() error { start := time.Now() var err error for time.Since(start) < LORAWAN_JOIN_TIMEOUT_SEC*time.Second { println("Trying to join network") err = lorawan.Join(otaa, session) if err == nil { println("Connected to network !") return nil } println("Join error:", err, "retrying in", LORAWAN_RECONNECT_DELAY_SEC, "sec") time.Sleep(time.Second * LORAWAN_RECONNECT_DELAY_SEC) } err = errors.New("Unable to join Lorawan network") println(err.Error()) return err } func failMessage(err error) { println("FATAL:", err) for { } } func main() { println("*** Lorawan basic join and uplink demo ***") // Board specific Lorawan initialization var err error radio, err = common.SetupLora() if err != nil { failMessage(err) } // Required for LoraWan operations session = &lorawan.Session{} otaa = &lorawan.Otaa{} // Connect the lorawan with the Lora Radio device. lorawan.UseRadio(radio) lorawan.UseRegionSettings(region.AU915()) // Configure AppEUI, DevEUI, APPKey, and public/private Lorawan Network setLorawanKeys() if debug != "" { println("main: Network joined") println("main: DevEui, " + otaa.GetDevEUI()) println("main: AppEui, " + otaa.GetAppEUI()) println("main: DevAddr, " + otaa.GetAppKey()) } // Try to connect Lorawan network if err := loraConnect(); err != nil { failMessage(err) } if debug != "" { println("main: NetID, " + otaa.GetNetID()) println("main: NwkSKey, " + session.GetNwkSKey()) println("main: AppSKey, " + session.GetAppSKey()) println("main: Done") } // Try to periodicaly send an uplink sample message upCount := 1 for { payload := "Hello TinyGo #" + strconv.Itoa(upCount) if err := lorawan.SendUplink([]byte(payload), session); err != nil { println("Uplink error:", err) } else { println("Uplink success, msg=", payload) } println("Sleeping for", LORAWAN_UPLINK_DELAY_SEC, "sec") time.Sleep(time.Second * LORAWAN_UPLINK_DELAY_SEC) upCount++ } }
Copy and past
TTN CREDENTIALS
//go:build !customkeys package main import ( "tinygo.org/x/drivers/lora/lorawan" ) // These are sample keys, so the example builds // Either change here, or create a new go file and use customkeys build tag func setLorawanKeys() { otaa.SetAppEUI([]uint8{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) otaa.SetDevEUI([]uint8{0x88, 0x57, 0x1D, 0xFF, 0xFE, 0xEE, 0x8C, 0x47}) otaa.SetAppKey([]uint8{0x46, 0x28, 0xCB, 0xB6, 0x4F, 0xF9, 0x4B, 0xA5, 0xB0, 0x04, 0xE2, 0xDC, 0x01, 0x9A, 0x89, 0xA2}) lorawan.SetPublicNetwork(true) }
AU915 Frequencies
au915.go
package region import "tinygo.org/x/drivers/lora" const ( AU915_DEFAULT_PREAMBLE_LEN = 8 AU915_DEFAULT_TX_POWER_DBM = 20 ) type RegionSettingsAU915 struct { joinRequestChannel *Channel joinAcceptChannel *Channel uplinkChannel *Channel } func AU915() *RegionSettingsAU915 { return &RegionSettingsAU915{ joinRequestChannel: &Channel{lora.MHz_916_8, lora.Bandwidth_125_0, lora.SpreadingFactor9, lora.CodingRate4_5, AU915_DEFAULT_PREAMBLE_LEN, AU915_DEFAULT_TX_POWER_DBM}, joinAcceptChannel: &Channel{lora.MHz_923_3, lora.Bandwidth_500_0, lora.SpreadingFactor9, lora.CodingRate4_5, AU915_DEFAULT_PREAMBLE_LEN, AU915_DEFAULT_TX_POWER_DBM}, uplinkChannel: &Channel{lora.MHz_916_8, lora.Bandwidth_125_0, lora.SpreadingFactor9, lora.CodingRate4_5, AU915_DEFAULT_PREAMBLE_LEN, AU915_DEFAULT_TX_POWER_DBM}, } } func (r *RegionSettingsAU915) JoinRequestChannel() *Channel { return r.joinRequestChannel } func (r *RegionSettingsAU915) JoinAcceptChannel() *Channel { return r.joinAcceptChannel } func (r *RegionSettingsAU915) UplinkChannel() *Channel { return r.uplinkChannel }
Compile and transfer
Success
TTN WORKSHOP
Questions: forums
Thanks to the
@deadprogram
@ofauchon
and Thanks too the
Ótima IDE para Go que aceita Plug in TinyGo
Release TinyGo
Or you can do the build
Road Map
- Clone the repository and checkout the feature branch
$ cd /tmp
$ git clone https://github.com/ofauchon/tinygo-drivers.git
$ cd tinygo-drivers
$ git checkout lorawan-regional-parameters
$ cd examples/lora/lorawan/basic-demo
- Tell go/tinygo you want to use this local repository as tinygo-driver sources:
$ cd examples/lora/lorawan/basic-demo
$ go mod init demo
$ edit go.mod and add the following line after "module demo"
replace tinygo.org/x/drivers => /tmp/tinygo-drivers
$ go mod tidy
- Update with your Lorawan Keys
$ vim keys-default.go
- Build or Flash your device
$ tinygo build -target=lorae5
$ tinygo flash -target=lorae5
Update
$ git pull
$ git checkout lorawan-cleanup
DRIVERS
C:\tmp\tinygo-drivers>tree
Listagem de caminhos de pasta
O número de série do volume é 42BE-2A44
C:.
├───.circleci
├───.github
│ └───workflows
├───adt7410
├───adxl345
├───aht20
├───amg88xx
├───apa102
├───apds9960
├───at24cx
├───axp192
│ └───m5stack-core2-axp192
├───bh1750
├───blinkm
├───bme280
├───bmi160
├───bmp180
├───bmp280
├───bmp388
├───buzzer
├───cmd
│ └───convert2bin
├───dht
├───ds1307
├───ds3231
├───easystepper
├───espat
├───examples
│ ├───adt7410
│ ├───adxl345
│ ├───aht20
│ ├───amg88xx
│ ├───apa102
│ │ └───itsybitsy-m0
│ ├───apds9960
│ │ ├───color
│ │ ├───gesture
│ │ └───proximity
│ ├───at24cx
│ ├───axp192
│ │ └───m5stack-core2-blinky
│ ├───bh1750
│ ├───blinkm
│ ├───bme280
│ ├───bmi160
│ ├───bmp180
│ ├───bmp280
│ ├───bmp388
│ ├───buzzer
│ ├───dht
│ ├───ds1307
│ │ ├───sram
│ │ └───time
│ ├───ds3231
│ ├───easystepper
│ ├───espat
│ │ ├───espconsole
│ │ ├───esphub
│ │ ├───espstation
│ │ ├───mqttclient
│ │ ├───mqttsub
│ │ └───tcpclient
│ ├───flash
│ │ └───console
│ │ ├───qspi
│ │ └───spi
│ ├───ft6336
│ │ ├───basic
│ │ └───touchpaint
│ ├───gc9a01
│ ├───gps
│ │ ├───i2c
│ │ └───uart
│ ├───hcsr04
│ ├───hd44780
│ │ ├───customchar
│ │ └───text
│ ├───hd44780i2c
│ ├───hts221
│ ├───hub75
│ │ └───gopherimg
│ ├───i2csoft
│ │ └───adt7410
│ ├───ili9341
│ │ ├───basic
│ │ ├───initdisplay
│ │ ├───pyportal_boing
│ │ │ └───graphics
│ │ ├───scroll
│ │ └───slideshow
│ ├───ina260
│ ├───irremote
│ ├───is31fl3731
│ ├───keypad4x4
│ ├───l293x
│ │ ├───simple
│ │ └───speed
│ ├───l3gd20
│ ├───l9110x
│ │ ├───simple
│ │ └───speed
│ ├───lis2mdl
│ ├───lis3dh
│ ├───lora
│ │ └───lorawan
│ │ ├───atcmd
│ │ ├───basic-demo
│ │ └───common
│ ├───lps22hb
│ ├───lsm303agr
│ ├───lsm6ds3
│ ├───lsm6ds3tr
│ ├───lsm6dsox
│ ├───lsm9ds1
│ ├───mag3110
│ ├───makeybutton
│ ├───max72xx
│ ├───mcp23017
│ ├───mcp23017-multiple
│ ├───mcp2515
│ ├───mcp3008
│ ├───microbitmatrix
│ ├───microphone
│ ├───mma8653
│ ├───mpu6050
│ ├───p1am
│ ├───pca9685
│ ├───pcd8544
│ │ ├───setbuffer
│ │ │ └───data
│ │ └───setpixel
│ ├───pcf8563
│ │ ├───alarm
│ │ ├───clkout
│ │ ├───time
│ │ └───timer
│ ├───qmi8658c
│ ├───rtl8720dn
│ │ ├───mqttclient
│ │ ├───mqttsub
│ │ ├───ntpclient
│ │ ├───tcpclient
│ │ ├───tlsclient
│ │ ├───udpstation
│ │ ├───version
│ │ ├───webclient
│ │ ├───webclient-tinyterm
│ │ └───webserver
│ ├───scd4x
│ ├───sdcard
│ │ ├───console
│ │ └───tinyfs
│ │ └───console
│ ├───semihosting
│ ├───servo
│ ├───sh1106
│ │ └───macropad_spi
│ ├───shifter
│ ├───shiftregister
│ ├───sht3x
│ ├───shtc3
│ ├───ssd1289
│ ├───ssd1306
│ │ ├───i2c_128x32
│ │ ├───i2c_128x64
│ │ └───spi_128x64
│ ├───ssd1331
│ ├───ssd1351
│ ├───st7735
│ ├───st7789
│ ├───sx126x
│ │ ├───lora_continuous
│ │ └───lora_rxtx
│ ├───sx127x
│ │ └───lora_rxtx
│ ├───thermistor
│ ├───tm1637
│ ├───tmp102
│ ├───tone
│ ├───touch
│ │ └───resistive
│ │ ├───fourwire
│ │ └───pyportal_touchpaint
│ ├───uc8151
│ ├───veml6070
│ ├───vl53l1x
│ ├───vl6180x
│ ├───waveshare-epd
│ │ ├───epd2in13
│ │ ├───epd2in13x
│ │ ├───epd2in9
│ │ └───epd4in2
│ ├───wifi
│ │ └───tcpclient
│ ├───wifinina
│ │ ├───connect
│ │ ├───http-get
│ │ ├───mqttclient
│ │ ├───mqttsub
│ │ ├───ntpclient
│ │ ├───pins
│ │ ├───tcpclient
│ │ ├───tlsclient
│ │ ├───udpstation
│ │ ├───webclient
│ │ └───webserver
│ ├───ws2812
│ └───xpt2046
├───flash
├───ft6336
├───gc9a01
├───gps
├───hcsr04
├───hd44780
├───hd44780i2c
├───hts221
├───hub75
├───i2csoft
├───ili9341
├───image
│ ├───internal
│ │ ├───compress
│ │ │ ├───flate
│ │ │ └───zlib
│ │ └───imageutil
│ ├───jpeg
│ └───png
├───ina260
├───irremote
├───is31fl3731
├───keypad4x4
├───l293x
├───l3gd20
├───l9110x
├───lis2mdl
├───lis3dh
├───lora
│ └───lorawan
│ └───region
├───lps22hb
├───lsm303agr
├───lsm6ds3
├───lsm6ds3tr
├───lsm6dsox
├───lsm9ds1
├───mag3110
├───makeybutton
├───max72xx
├───mcp23017
├───mcp2515
├───mcp3008
├───microbitmatrix
├───microphone
├───mma8653
├───mpu6050
├───net
│ ├───http
│ │ └───cookiejar
│ ├───mqtt
│ └───tls
├───p1am
│ └───internal
│ └───cmd
│ └───gen_defines
├───pca9685
├───pcd8544
├───pcf8563
├───qmi8658c
├───rtl8720dn
├───scd4x
├───sdcard
├───semihosting
├───servo
├───sh1106
├───shifter
├───shiftregister
├───sht3x
├───shtc3
├───ssd1289
├───ssd1306
├───ssd1331
├───ssd1351
├───st7735
├───st7789
├───sx126x
├───sx127x
├───tester
├───thermistor
├───tm1637
├───tmp102
├───tone
├───touch
│ └───resistive
├───uc8151
├───veml6070
├───vl53l1x
├───vl6180x
├───waveshare-epd
│ ├───epd2in13
│ ├───epd2in13x
│ ├───epd2in9
│ └───epd4in2
├───wifinina
│ ├───protocol
│ └───updater
├───ws2812
└───xpt2046
TO DO
Downlink messages
References:
About SmartCore
SmartCore provides modules for wireless communication, biometrics, connectivity, tracking and automation.Our portfolio includes 2G/3G/4G/NB-IoT/Cat.M modem, satellite, WiFi modules, Bluetooth, GNSS / GPS, Sigfox, LoRa, card reader, QR code reader, print engine, mini-board PC, antenna, pigtail, LCD, battery, GPS repeater and sensors.More details at www.smartcore.com.br
SmartCore provides modules for wireless communication, biometrics, connectivity, tracking and automation.
Our portfolio includes 2G/3G/4G/NB-IoT/Cat.M modem, satellite, WiFi modules, Bluetooth, GNSS / GPS, Sigfox, LoRa, card reader, QR code reader, print engine, mini-board PC, antenna, pigtail, LCD, battery, GPS repeater and sensors.
More details at www.smartcore.com.br
Nenhum comentário:
Postar um comentário