Main Site Documentation

Exception for open an UDP socket


#1

Hello, I try to create a communication between my pc and an UC5550 by wifi and udp. I have read this example: Network samples? for setup the wifi. my UC5550 is corectly connected to my network but when I try to open a socket that generate an exception :

#### Exception System.Exception - 0x00000000 (1) ####
#### Message: Request failed
#### GHIElectronics.TinyCLR.Networking.SPWF04Sx.SPWF04SxInterface::OpenSocket [IP: 0083] ####
#### TestApli.Program::Main [IP: 00a5] ####
Exception levée : 'System.Exception' dans GHIElectronics.TinyCLR.Networking.SPWF04Sx.dll
Une exception non gérée du type 'System.Exception' s'est produite dans  
GHIElectronics.TinyCLR.Networking.SPWF04Sx.dll
Informations supplémentaires : Request failed

my code:


I don’t know if I use correctly the method OpenSocket.


#2

Is the address you are supplying the device (local) address or the remote?

From here: https://forums.ghielectronics.com/t/network-samples/21609/8, you may need to put a sleep between
wifi.TurnOn();

and

          var id = wifi.OpenSocket("192.168.43.3", 52592, SPWF04SxConnectionyType.Udp, SPWF04SxConnectionSecurityType.None);'

I know in the DNMF there were events to notify the app layer when the network/wifi was ready, and when it was connected/disconnected. Not sure about TinyCLR


#3

Is the address you are supplying the device (local) address or the remote?

It’s a local adress.

From here: https://forums.ghielectronics.com/t/network-samples/21609/8, you may need to put a sleep

I have a method Waitforbutton() so I do my-self the delay.They are a feedback of the connection in the console with this:

wifi.IndicationReceived += (s, e) => Debug.WriteLine($"WIND: {WindToName(e.Indication)} {e.Message}");
wifi.ErrorReceived += (s, e) => Debug.WriteLine($"ERROR: {e.Error} {e.Message}");

#4

Do you need to provide the remote address, i.e. the address to/from which you’re going to tx/rx the data on that UDP port?


#5

Also, where do u set up the wifi settings (like access point name, pwd?)

I just noticed that no where prior to OpenSocket call do you set dhc or static ip address, nor do you tell the spwf04 which SSID to connect to…

If the wifi radio (SPWF04Sx) of your device isn’t connected to a network, then trying to open a socket should fail.


#6

The spwf04 keep in memory the wifi settings so we can use only one JoinNetwork(“ssid”, “password”). I see the connection is OK on the console and I see too my UC5550 is a connected device on my wifi.


#7

Ok, but it wasn’t in your code above…

Try using the address “192.168.43.255”. This is the broadcast UDP address, and should work. If that works, you can try the address of what ever device you’re trying to send data to (if you don’t want the data broadcast to everyone on the network).

Is it the address of the SPWF04Sx, or a pc or something else on the network?


#8

It’s the address of a pc.I have already test with the broadcast address and I had the same error.


#9

Your code looks correct. We do have another release coming soon that you may want to try. In the mean time, you can always add the code for the SPWF04SA to your project from our GitHub and step through the OpenSocket call to see what result you get back from the device. You may need to update a few bits of the code to use the current preview 1 release if you don’t want for preview 2.


#10

I have tried the preview 2 and I have added the driver code to my project. I have found the probleme but I don’t know how resolve It.


The SPWF04S return “adress:id” but there is not “On”. What does it mean ?


#11

Looks like UDP returns a different format than TCP does. Try changing that line in question to:

return a.Split(':') is string[] result ? int.Parse(result[1]) : throw new Exception("Request failed");