sábado, 24 de dezembro de 2022

WISOL LSM110A RODANDO TinyGo - LoRaWAN

                                    WISOL LSM110A  RODANDO TINYGO IDE GOLANG - LoRaWAN


O objetivo deste BLOG é demonstrar como é possível programar o módulo WISOL LSM110A (STM32WL55) com a linguagem TinyGo, foi utilizado o Breakout para LSM110A.

BETA BETA BETA BETA

Uma comunicação com servidor LoRaWAN ChirpStack e TTTN será realizada (OTAA, AU915), um texto Hello TinyGo #XX será enviado a cada 60 segundos, o #XX é um contador.

Requer seu conhecimento em  Go/TinyGo

Acompanhe discussão em



LSM110A Starter KIT

Módulo

Breakout

O que é ChirpStack

ChirpStack é um Servidor de Rede LoRaWAN de código aberto que pode ser usado para configurar redes LoRaWAN. O ChirpStack fornece uma interface web para o gerenciamento de gateways, dispositivos e inquilinos, bem como para configurar integrações de dados com os principais provedores de nuvem, bancos de dados e serviços comumente usados para lidar com dados de dispositivos. O ChirpStack fornece uma API baseada em gRPC que pode ser usada para integrar ou estender o ChirpStack.

O que é TTN

A Rede de Coisas (TTN) é uma iniciativa iniciada pela sociedade civil holandesa. O objetivo é ter redes LoRaWAN instaladas em todas as cidades do mundo. Ao interconectar essas redes locais, a TTN quer construir uma infra-estrutura mundial para facilitar uma Internet das Coisas (IoT) pública.

TinyGO

TinyGo é um projeto para levar a linguagem de programação Go para microcontroladores e navegadores modernos, criando um novo compilador baseado em LLVM.

Você pode compilar e executar programas TinyGo em muitas placas microcontroladoras diferentes, como o micro:bit da BBC e o Arduino Uno.

TinyGo também pode ser usado para produzir código WebAssembly (WASM), que é muito compacto em tamanho.

Só quer ver o código? Vá ao repositório do Github em 


TinyGo também tem suporte para vários dispositivos diferentes, como acelerômetros e magnetômetros. Confira o repositório do Github em 

https://github.com/tinygo-org/drivers para obter mais informações.

Atenção:

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++ } }
Copie e cole

Pegue/cadastre suas credenciais do/no ChirpStack ou TTN




keys-default.go



//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) }






Frequências para AU915

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 e grave



Conexão

Ainda portando para AU915

SUCESSO




ACOMPANHE DISCUSSÃO


TTN WORKSHOP



Questões: forums

Thanks to the
@deadprogram 
@ofauchon 

and Thanks too the

Ótima IDE para Go que aceita Plug in TinyGo

Release TinyGo


Ou podes fazer o Build





Roteiro

  1. 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
  1. 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
  1. Update with your Lorawan Keys
$ vim keys-default.go
  1. Build or Flash your device
$ tinygo build -target=lorae5 
$ tinygo flash -target=lorae5 

Atualização

$ 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

FONTES: 

Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portfólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br