Main Site Documentation

AD-HOC example


#1

Any Ad-HOC example of RedPine Module ? Anybody tried ? When can I sense if someone connected ( when im the creator) ? Help apreciated :stuck_out_tongue:


#2

Got The Ad Hoc to work - but got some questions - The WEP how to set it ? I set it and can always connect :confused: + Can I “know” who is trying to connect ( and grant or deny acces ? ) ? Can I make the SSID hidden ? Thx for any advice

WiFi.ConnectAdHoc(WiFi.IBSSMode.Creator, "MyWiFi", SecurityMode.WEP,"1A648C9FE2", 1);

#3

General wireless networking tip: hidden SSID is actually more insecure than not, and no longer recommended; there are network stacks that won’t connect to a hidden SSID so you may get yourself in more trouble than its worth.


#4

WiFi Class has been totally changed. We will release the new SDK this week hopefully. Stay tuned.

Here is the new example code sneek peek:

public class Program
    {

        public static void Main()
        {
            //ChipworkX Developement System V1.5 UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
            //SPI.SPI_module _spi = SPI.SPI_module.SPI2; /*SPI bus*/
            //Cpu.Pin _cs = ChipworkX.Pin.PC9; /*ChipSelect*/
            //Cpu.Pin _ExtInt = ChipworkX.Pin.PA19; /*External Interrupt*/
            //Cpu.Pin _reset = ChipworkX.Pin.PC8; /*Reset*/
            /*-------------------------------------------------------------------*/
            //EMX Developement System V1.3 UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
            SPI.SPI_module _spi = SPI.SPI_module.SPI1; /*SPI bus*/
            Cpu.Pin _cs = EMX.Pin.IO2; /*ChipSelect*/
            Cpu.Pin _ExtInt = EMX.Pin.IO26; /*External Interrupt*/
            Cpu.Pin _reset = EMX.Pin.IO3; /*Reset*/
            /*-------------------------------------------------------------------*/
            //FEZ Cobra OEM board V1.2 or V1.3 UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
            //SPI.SPI_module _spi = SPI.SPI_module.SPI2; /*SPI bus*/
            //Cpu.Pin _cs = EMX.Pin.IO2; /*ChipSelect*/
            //Cpu.Pin _ExtInt = EMX.Pin.IO26; /*External Interrupt*/
            //Cpu.Pin _reset = EMX.Pin.IO3; /*Reset*/
            /*-------------------------------------------------------------------*/

            Debug.Print("Enable WiFi RS2 module");

            try
            {
                //ChipworkX Developement System UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
                WiFi.Enable(WiFi.HardwareModule.RS9110_N_11_21_1_Compatible,
                            _spi,/*SPI bus*/
                            _cs,  /*ChipSelect*/
                            _ExtInt, /*External Interrupt*/
                            _reset); /*Reset*/
            }
            catch (WiFi.WiFiException e)
            {
                if (e.errorCode == WiFi.WiFiException.ErrorCode.HardwareCommunicationFailure ||
                    e.errorCode == WiFi.WiFiException.ErrorCode.HardwareFirmwareVersionMismatch)
                {
                    //ChipworkX Developement System UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
                    WiFi.UpdateFirmware(WiFi.HardwareModule.RS9110_N_11_21_1_Compatible,
                                        _spi,/*SPI bus*/
                                        _cs,  /*ChipSelect*/
                                        _ExtInt, /*External Interrupt*/
                                        _reset); /*Reset*/
                    WiFi.Enable(WiFi.HardwareModule.RS9110_N_11_21_1_Compatible,
                                 _spi,/*SPI bus*/
                                 _cs,  /*ChipSelect*/
                                 _ExtInt, /*External Interrupt*/
                                 _reset); /*Reset*/
                }
                else if (e.errorCode == WiFi.WiFiException.ErrorCode.HardwareCommunicationFailure)
                {
                    Debug.Print("Error Message: " + e.ErrorMsg);
                    Debug.Print("Check WiFi module hardware connections and SPI/signals configurations.");
                    throw;
                }
            }

            if (WiFi.IsEnabled)
                Debug.Print("Enabled Successfully. At this point, the on-board LED on RS9110_N_11_21_1_Compatible module is ON.");
            else
                throw new Exception();

            // This event handler checks netowrk avaialblty (Ethernet, WiFi and PPP).
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);

            //WiFi.StartAdHocHost("Ad-Hoc Test", SecurityMode.Open, "", 10);
            WiFi.StartAdHocHost("Ad-Hoc Test WEP", SecurityMode.WEP, "A1CEF53456A1CEF53456AF34DB", 10); // 128bit key (26 Hex numbers)
            //WiFi.StartAdHocHost("Ad-Hoc Test WEP", SecurityMode.WEP, "A1CEF53456A", 10); // 64bit key (10 Hex numbers)
            Debug.Print("Join the other peer of Ad-Hoc connection");
            NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces();
            netif[0].EnableStaticIP("192.168.137.2", "255.255.255.0", "0.0.0.0");
            Debug.Print("Set the other peer's IP to 192.168.137.1");
            Debug.Print("Try to ping this IP from the other peer 192.168.137.2");
            Thread.Sleep(10000);
            Debug.Print("Disconnect WiFi link.");
            WiFi.Disconnect();
            Debug.Print("Disable WiFi interface");
            WiFi.Disable();
            Debug.Print("The end of test");
            Thread.Sleep(Timeout.Infinite);
        }


        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network Availability Event Triggered");
            if (e.IsAvailable)
            {
                if (WiFi.IsEnabled)// Make sure that the event is fired by WiFi interface, not other networking interface.
                    if (WiFi.IsLinkConnected)
                    {

                        Debug.Print("Ad-Hoc Host started.");
                    }
            }
            else
            {
                if (WiFi.IsEnabled)// Make sure that the event is fired by WiFi interface, not other networking interface.
                    if (!WiFi.IsLinkConnected)
                    {

                        Debug.Print("WiFi connection was dropped or disconnected!");
                    }
            }
        }

#5

Does


  static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network Availability Event Triggered");
            if (e.IsAvailable)
            {
                if (WiFi.IsEnabled)// Make sure that the event is fired by WiFi interface, not other networking interface.
                    if (WiFi.IsLinkConnected)
                    {
 
                        Debug.Print("Ad-Hoc Host started.");
                    }
            }
            else
            {
                if (WiFi.IsEnabled)// Make sure that the event is fired by WiFi interface, not other networking interface.
                    if (!WiFi.IsLinkConnected)
                    {
 
                        Debug.Print("WiFi connection was dropped or disconnected!");
                    }
            }
        }

This event occur only when i activate a new netwokr, and IsLinkConnected mean an actuall connection to a client ?


#6

[quote]This event occur only when i activate a new netwokr, and IsLinkConnected mean an actuall connection to a client ?
[/quote]

only when you activate a new network.


#7

Do you provide some interface to check the signal strength during a connection. Or perhaps signal strength of surrounding networks ? Just thinking :stuck_out_tongue:


#8

Yes it is the RSSI


#9

Thanks Joe…loking forward to this. 8)