Esempio n. 1
0
        private void TimerTick_Startup(Gadgeteer.Timer timer)
        {
            //INITIALIZING : SD Storage
            Debug.Print("CobraII: Initializing memory card storage...");

            if (Mainboard.IsSDCardInserted && Mainboard.IsSDCardMounted)
            {
                StorageDevice sd = Mainboard.SDCardStorageDevice;

                if (sd.Volume.IsFormatted)
                {
                    Server = new ServiceManager(LogType.Output, LogLevel.Debug, sd.RootDirectory);
                }
            }
            else
            {
                Server = new ServiceManager(LogType.Output, LogLevel.Debug, null);
            }

            //INITIALIZING : Wireless
            Debug.Print("CobraII: Initializing wireless network...");

            if (!netWifi.Opened)
            {
                netWifi.Open();
            }

            WiFiRS9110.NetworkParameters wifiParms = new WiFiRS9110.NetworkParameters();
            wifiParms.NetworkType  = WiFiRS9110.NetworkType.AdHoc;
            wifiParms.SecurityMode = WiFiRS9110.SecurityMode.Open;
            wifiParms.Ssid         = "cobra";
            wifiParms.Key          = "";       //GetWepBytes("1234567890");  // must be 10 or 26 digits
            wifiParms.Channel      = 6;
            netWifi.StartAdHocNetwork(wifiParms);
            Debug.Print("CobraII: Started AdHoc Network: SSID=" + wifiParms.Ssid);

            netWifi.EnableStaticIP("192.168.50.1", "255.255.255.0", "192.168.50.1");
            netWifi.EnableStaticDns(new string[] { "192.168.50.1" });

            if (!netWifi.LinkConnected)
            {
                while (netWifi.NetworkInterface.IPAddress == "0.0.0.0")
                {
                    Debug.Print("CobraII: Waiting for DHCP...");
                    Thread.Sleep(1000);
                }
            }
            //INITIALIZING : MicroServer
            InitMicroServer();
        }
Esempio n. 2
0
        void ConnectToNetwork()
        {
            Debug.Print("Connecting network.");

            int       connectionAttempt      = 0;
            const int MAX_CONNECTION_ATTEMPT = 10;

            wifiRS21.NetworkUp += wifiRS21_NetworkUp;
            wifiRS21.NetworkInterface.Open();


            wifiRS21.UseStaticIP(
                "192.168.1.20",
                "255.255.255.0",
                "192.168.1.1",
                new string[] {
                "8.8.8.8",
                "8.8.4.4"
            }
                );

            WiFiRS9110.NetworkParameters networkParameters = new WiFiRS9110.NetworkParameters();
            networkParameters.Ssid = "Plain Concepts";
            networkParameters.Key  = "abra.cadabra.77";

            networkParameters.Channel      = 11;
            networkParameters.NetworkType  = WiFiRS9110.NetworkType.AccessPoint;
            networkParameters.SecurityMode = WiFiRS9110.SecurityMode.Wpa2;

            while (connectionAttempt < MAX_CONNECTION_ATTEMPT && !wifiRS21.IsNetworkConnected)
            {
                try
                {
                    var networks = wifiRS21.NetworkInterface.Scan(networkParameters.Ssid);
                    wifiRS21.NetworkInterface.Join(networkParameters);
                }
                catch (Exception ex)
                {
                    //Keep trying to connect.
                    Debug.Print(ex.ToString());
                }

                Thread.Sleep(1000);
            }

            Debug.Print("Network is connected: " + wifiRS21.IsNetworkConnected);
        }
Esempio n. 3
0
        private void TimerTick_Startup(Gadgeteer.Timer timer)
        {
            //INITIALIZING : SD Storage
            Debug.Print("CobraII: Initializing memory card storage...");

            if (Mainboard.IsSDCardInserted && Mainboard.IsSDCardMounted)
            {
                StorageDevice sd = Mainboard.SDCardStorageDevice;

                if (sd.Volume.IsFormatted)
                {
                    Server = new ServiceManager(LogType.Output, LogLevel.Debug, sd.RootDirectory);
                }
            }
            else
            {
                Server = new ServiceManager(LogType.Output, LogLevel.Debug, null);
            }

            //INITIALIZING : Wireless
            Debug.Print("CobraII: Initializing wireless network...");

            if (!netWifi.Opened)
                netWifi.Open();

            WiFiRS9110.NetworkParameters wifiParms = new WiFiRS9110.NetworkParameters();
            wifiParms.NetworkType = WiFiRS9110.NetworkType.AdHoc;
            wifiParms.SecurityMode = WiFiRS9110.SecurityMode.Open;
            wifiParms.Ssid = "cobra";
            wifiParms.Key = "";                //GetWepBytes("1234567890");  // must be 10 or 26 digits
            wifiParms.Channel = 6;
            netWifi.StartAdHocNetwork(wifiParms);
            Debug.Print("CobraII: Started AdHoc Network: SSID=" + wifiParms.Ssid);

            netWifi.EnableStaticIP("192.168.50.1", "255.255.255.0", "192.168.50.1");
            netWifi.EnableStaticDns(new string[] { "192.168.50.1" });

            if (!netWifi.LinkConnected)
            {
                while (netWifi.NetworkInterface.IPAddress == "0.0.0.0")
                {
                    Debug.Print("CobraII: Waiting for DHCP...");
                    Thread.Sleep(1000);
                }
            }
            //INITIALIZING : MicroServer
            InitMicroServer();
        }
Esempio n. 4
0
        // This method is run when the mainboard is powered up or reset.
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            #region ForEthernet
            //ethernetJ11D.UseThisNetworkInterface();
            //ethernetJ11D.UseStaticIP("192.168.137.1","255.255.255.0","192.168.137.46");

            //ethernetJ11D.NetworkUp += ethernetJ11D_NetworkUp;
            //ethernetJ11D.NetworkDown += ethernetJ11D_NetworkDown;
            #endregion

            /*Inizialized Database for Misure*/
            sqldb = new SQL_Wrapper(sdCard);
            sqldb.setup_database();

            /*Create Configuration*/
            //Configuration conf = new Configuration();
            StreamReader d = new StreamReader(sdCard.StorageDevice.RootDirectory + "\\configuration.json");
            configuration = d.ReadToEnd();

            /*Inizialized DHT11 sensor*/
            init = new InizializeDHT();

            /*Start Timer for read sensors*/
            GT.Timer t6sec = new GT.Timer(6000);
            t6sec.Tick += read_sensors;
            t6sec.Start();

            /*Start Timer for Backup DataBase*/
            //GT.Timer tBackup = new GT.Timer(1000 * 60 * 7); //7 minuti
            //tBackup.Tick += BackupDB;
            //tBackup.Start();

            /*Activate WiFi interface*/
            WiFiRS9110.NetworkParameters mynet = new WiFiRS9110.NetworkParameters();
            if (!wifiRS21.NetworkInterface.Opened)
            {
                wifiRS21.NetworkInterface.Open();
            }
            wifiRS21.UseThisNetworkInterface();

            #region AdHoc
            //mynet.Channel= 5;
            //mynet.Ssid="prova";
            //mynet.Key=" ";
            //mynet.SecurityMode = WiFiRS9110.SecurityMode.Open;
            //mynet.NetworkType = WiFiRS9110.NetworkType.AdHoc;
            ////wifiRS21.NetworkInterface.EnableStaticIP("192.168.1.100", "255.255.0.0", "192.168.1.1");
            //wifiRS21.NetworkInterface.StartAdHocNetwork(mynet);



            //Thread.Sleep(2000);
            //HttpListener l = new HttpListener("http");

            //l.Start();
            //var contex = l.GetContext();
            //var respons = contex.Response;

            //const string r = "<html><body>Hello world</body></html>";
            //var buffer = System.Text.Encoding.UTF8.GetBytes(r);
            //respons.ContentLength64 = buffer.Length;
            //var output = respons.OutputStream;
            //output.Write(buffer, 0, buffer.Length);
            //output.Close();
            #endregion

            /*Connect to wifi*/
            wifiC = new WiFiConnection();
            wifiC.WifiConnected += wifiC_WifiConnected;
            wifiC.connectToWiFI(wifiRS21, SSID, PASSWORD);

            //setup();
        }