mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-18 13:43:58 +00:00
Fix RSSI command for WiFiNINA
+ Print current SSID + Wait for correct time before printing it out + Cleanup
This commit is contained in:
@@ -52,15 +52,37 @@ func main() {
|
|||||||
connectToAP()
|
connectToAP()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
println("---------------------------------")
|
println("----------------------------------------")
|
||||||
|
printSSID()
|
||||||
|
printRSSI()
|
||||||
|
printMac()
|
||||||
printIPs()
|
printIPs()
|
||||||
printTime()
|
printTime()
|
||||||
printMacAddress()
|
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printSSID() {
|
||||||
|
print("SSID: ")
|
||||||
|
ssid, err := adaptor.GetCurrentSSID()
|
||||||
|
if err != nil {
|
||||||
|
println("Unknown (error: ", err.Error(), ")")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(ssid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printRSSI() {
|
||||||
|
print("RSSI: ")
|
||||||
|
rssi, err := adaptor.GetCurrentRSSI()
|
||||||
|
if err != nil {
|
||||||
|
println("Unknown (error: ", err.Error(), ")")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(fmt.Sprintf("%d", rssi))
|
||||||
|
}
|
||||||
|
|
||||||
func printIPs() {
|
func printIPs() {
|
||||||
ip, subnet, gateway, err := adaptor.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,20 +91,28 @@ func printIPs() {
|
|||||||
}
|
}
|
||||||
println("IP: ", ip.String())
|
println("IP: ", ip.String())
|
||||||
println("Subnet: ", subnet.String())
|
println("Subnet: ", subnet.String())
|
||||||
println("Gateway IP: ", gateway.String())
|
println("Gateway: ", gateway.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTime() {
|
func printTime() {
|
||||||
print("Time: ")
|
print("Time: ")
|
||||||
t, err := adaptor.GetTime()
|
t, err := adaptor.GetTime()
|
||||||
if err != nil {
|
for {
|
||||||
println("Unknown (error: ", err.Error(), ")")
|
if err != nil {
|
||||||
|
println("Unknown (error: ", err.Error(), ")")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t != 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
t, err = adaptor.GetTime()
|
||||||
}
|
}
|
||||||
println(time.Unix(int64(t), 0).String())
|
println(time.Unix(int64(t), 0).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func printMacAddress() {
|
func printMac() {
|
||||||
print("MAC Address: ")
|
print("MAC: ")
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
mac, err := adaptor.GetMACAddress()
|
mac, err := adaptor.GetMACAddress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -115,16 +145,12 @@ func connectToAP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
message("Connecting to " + ssid)
|
println("Connecting to " + ssid)
|
||||||
adaptor.SetPassphrase(ssid, pass)
|
adaptor.SetPassphrase(ssid, pass)
|
||||||
for st, _ := adaptor.GetConnectionStatus(); st != wifinina.StatusConnected; {
|
for st, _ := adaptor.GetConnectionStatus(); st != wifinina.StatusConnected; {
|
||||||
message("Connection status: " + st.String())
|
println("Connection status: " + st.String())
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
st, _ = adaptor.GetConnectionStatus()
|
st, _ = adaptor.GetConnectionStatus()
|
||||||
}
|
}
|
||||||
message("Connected.")
|
println("Connected.")
|
||||||
}
|
|
||||||
|
|
||||||
func message(msg string) {
|
|
||||||
println(msg, "\r")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -484,7 +484,7 @@ func (d *Device) GetCurrentBSSID() (MACAddress, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) GetCurrentRSSI() (int32, error) {
|
func (d *Device) GetCurrentRSSI() (int32, error) {
|
||||||
return d.getInt32(d.req1(CmdGetCurrBSSID))
|
return d.getInt32(d.req1(CmdGetCurrRSSI))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) GetCurrentSSID() (string, error) {
|
func (d *Device) GetCurrentSSID() (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user