This project includes a Netduino Plus 2, a photo sensor and a RN-XV WiFly module (with wireless shield).
What I am aiming for is that when the application starts a connection is made to the wifi network; then when the photo sensor is triggered a counter variable is sent to a webpage, as a querystring variable, to add it to a database.
Before I create the HTTP request I thought I would make sure I can access the WiFly "instance" from within the OnInterrupt "function/call" by simply getting the Local IP address again and writing it to the Debug window (apologies again if I'm getting the terminology wrong).
There is no problem populating the string "strLocalIP_1" but as soon as I try populate "strLocalIP_2" the application hangs.
What am I missing?
using System; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using Toolbox.NETMF; using Toolbox.NETMF.NET; using Toolbox.NETMF.Hardware; namespace sandbox { public class Program { // declare counter variable, photoSensor and wifly static uint counter = 0; static InterruptPort mySensor; static WiFlyGSX WifiModule; public static void Main() { // Create sensor instance mySensor = new InterruptPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); mySensor.OnInterrupt += new NativeEventHandler(mySensor_OnInterrupt); // Create WiFly instance WifiModule = new WiFlyGSX(); // Allow some time for WiFly to power up and find network Thread.Sleep(5000); // Join Network WifiModule.EnableDHCP(); WifiModule.JoinNetwork("SSID", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "Password"); // Wait for authentication and joining Thread.Sleep(5000); Debug.Print("WiFi connected"); // Get the Local IP to confirm connection to the wifi network string strLocalIP_1; strLocalIP_1 = WifiModule.LocalIP; Debug.Print(strLocalIP_1); // Indefinitely wait for any sensor interrupts... Thread.Sleep(Timeout.Infinite); } public static void mySensor_OnInterrupt(uint port, uint state, DateTime time) { // get the "interrupt" state to stop counter counting twice if (state == 0) { // Write the count to the debug window Debug.Print("counter: " + counter); // Get the Local IP to confirm connection to the wifi network string strLocalIP_2; strLocalIP_2 = WifiModule.LocalIP; Debug.Print(strLocalIP_2); // increase counter by 1 counter++; } } } }
I'm sure it's a real noob oversight on my part but would appreciate any help.
Thanks,
Donovan