B4R Question wifi shield

Erel

B4X founder
Staff member
Licensed User
Longtime User
Currently there is no library available for the wifi shield.

Actually I did start to implement a wifi library with the MKR1000 board. However there were too many driver issues with this board that made development difficult.

You can try the attached library if you like.

You need to first install WiFi101 from the Arduino IDE:

SS-2016-05-31_13.58.13.png


B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private wifi As WiFi101
   Private const ssid As String = "dlink"
   Private client As WiFiSocket
   Private astream As AsyncStreams
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart2")
   ScanNetworks
   If wifi.Connect(ssid) Then 'open network. Use ConnectWPA to connect to a secure network
     ConnectToServer
   End If
End Sub


Private Sub ConnectToServer
   If client.ConnectIP(Array As Byte(192,168,0,6), 51042, False) Then
     Log("Connected to server")
     astream.Initialize(client.Stream, "astream_NewData", "astream_Error")
  
     timer1.Initialize("timer1_Tick", 1000)
     timer1.Enabled = True
   End If
End Sub

Sub Timer1_Tick
   Log("timer")
   astream.Write(NumberFormat(Millis, 0, 0))
End Sub

Sub astream_NewData (Buffer() As Byte)
   Log("newdata: ", Buffer)
End Sub

Sub astream_Error
   Log("Error")

End Sub

Private Sub ScanNetworks
   Log("Scanning for networks.")
   Dim num As Int = wifi.ScanNetworks
   Log("Found: ", num, " networks.")
   For i= 0 To  num - 1
     Log("SSID: ", wifi.SSID(i), ", RSSI: ", wifi.RSSI(i), ", encryption type: ", wifi.EncryptionType(i))
   Next
End Sub
 

Attachments

  • rWiFi101.zip
    2.4 KB · Views: 316
Last edited:
Upvote 0

soltypio

Member
Licensed User
Longtime User
Hi,
Is attached file a working library (it contains only one XML file)?

p.s. I have wifi101 lib working fine with MKR1000 in Arduino IDE installed (ver. 0.7.0 - reported to work fine with MKR1000 boards), but above exapmple gives file not found error during compilation. Compiler expects rWifi101.h file....
 
Upvote 0

soltypio

Member
Licensed User
Longtime User
wow, that was fast! according to posting time showed above, you answered about 4 hours before I asked :).
Thank you very much!
 
Upvote 0
Top