Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wifinina: add generated strings, improved debugging system and messages #560

Merged
merged 2 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions wifinina/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ Verify correct version of nina-fw installed by flasing `CheckFirmwareVersion.ino
Adafruit provides very good instructions for updating their boards that provide a ESP32 WiFi-BLE co-processor. For more information, please see:

https://learn.adafruit.com/upgrading-esp32-firmware

## Updating the driver

If you modify the WiFiNINA status or command codes, you will also need to regenerate the display strings.

```
go generate ./wifinina/status.go ./wifinina/commands.go
```

## Debugging

You can output debug information to the serial console by using the `wifidebug` tag.

```
tinygo flash -target pyportal -ldflags="-X main.ssid=something -X main.pass=somethingelse" -tags=wifidebug -monitor ./examples/wifinina/webclient/
```
67 changes: 67 additions & 0 deletions wifinina/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package wifinina

type CommandType uint8

//go:generate stringer -type=CommandType -trimprefix=Cmd
const (
CmdStart CommandType = 0xE0
CmdEnd CommandType = 0xEE
CmdErr CommandType = 0xEF

CmdSetNet CommandType = 0x10
CmdSetPassphrase CommandType = 0x11
CmdSetKey CommandType = 0x12
CmdSetIPConfig CommandType = 0x14
CmdSetDNSConfig CommandType = 0x15
CmdSetHostname CommandType = 0x16
CmdSetPowerMode CommandType = 0x17
CmdSetAPNet CommandType = 0x18
CmdSetAPPassphrase CommandType = 0x19
CmdSetDebug CommandType = 0x1A
CmdGetTemperature CommandType = 0x1B
CmdGetReasonCode CommandType = 0x1F
// TEST_CMD = 0x13

CmdGetConnStatus CommandType = 0x20
CmdGetIPAddr CommandType = 0x21
CmdGetMACAddr CommandType = 0x22
CmdGetCurrSSID CommandType = 0x23
CmdGetCurrBSSID CommandType = 0x24
CmdGetCurrRSSI CommandType = 0x25
CmdGetCurrEncrType CommandType = 0x26
CmdScanNetworks CommandType = 0x27
CmdStartServerTCP CommandType = 0x28
CmdGetStateTCP CommandType = 0x29
CmdDataSentTCP CommandType = 0x2A
CmdAvailDataTCP CommandType = 0x2B
CmdGetDataTCP CommandType = 0x2C
CmdStartClientTCP CommandType = 0x2D
CmdStopClientTCP CommandType = 0x2E
CmdGetClientStateTCP CommandType = 0x2F
CmdDisconnect CommandType = 0x30
CmdGetIdxRSSI CommandType = 0x32
CmdGetIdxEncrType CommandType = 0x33
CmdReqHostByName CommandType = 0x34
CmdGetHostByName CommandType = 0x35
CmdStartScanNetworks CommandType = 0x36
CmdGetFwVersion CommandType = 0x37
CmdSendDataUDP CommandType = 0x39
CmdGetRemoteData CommandType = 0x3A
CmdGetTime CommandType = 0x3B
CmdGetIdxBSSID CommandType = 0x3C
CmdGetIdxChannel CommandType = 0x3D
CmdPing CommandType = 0x3E
CmdGetSocket CommandType = 0x3F
// GET_IDX_SSID_CMD = 0x31,
// GET_TEST_CMD = 0x38

// All command with DATA_FLAG 0x40 send a 16bit Len
CmdSendDataTCP CommandType = 0x44
CmdGetDatabufTCP CommandType = 0x45
CmdInsertDataBuf CommandType = 0x46

// regular format commands
CmdSetPinMode CommandType = 0x50
CmdSetDigitalWrite CommandType = 0x51
CmdSetAnalogWrite CommandType = 0x52
)
120 changes: 120 additions & 0 deletions wifinina/commandtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions wifinina/connectionstatus_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions wifinina/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build wifidebug

package wifinina

var _debug = true
44 changes: 44 additions & 0 deletions wifinina/encryptiontype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions wifinina/error_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wifinina/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ func (c *client) stop() error {
}

// Wait max 5 secs for the connection to close
for i := 0; i < 50 && c.status() != TCPStateClosed; i++ {
for i := 0; i < 50 && c.status() != uint8(TCPStateClosed); i++ {
time.Sleep(100 * time.Millisecond)
}

if c.status() != TCPStateClosed {
if c.status() != uint8(TCPStateClosed) {
return fmt.Errorf("stop failed, client status %x", c.status())
}

Expand Down
5 changes: 5 additions & 0 deletions wifinina/nodebug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !wifidebug

package wifinina

var _debug = false
Loading