peony3000

Gadgeteer Data Logging 01 Bugged

Apr 2nd, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT;
  4. using Gadgeteer.Networking;
  5. using GT = Gadgeteer;
  6. using GTM = Gadgeteer.Modules;
  7. using Gadgeteer.Modules.GHIElectronics;
  8.  
  9.  
  10. namespace Gadgeteer_eMail_01
  11. {
  12.     public partial class Program
  13.     {
  14.         // create a time based event robot to trigger repeated tasks
  15.         GT.Timer timer = new GT.Timer(60000, GT.Timer.BehaviorType.RunContinuously);
  16.  
  17.         // This method is run when the mainboard is powered up or reset.  
  18.         void ProgramStarted()
  19.         {
  20.            
  21.             // tell everyone that you have started
  22.             Debug.Print("Program Started");
  23.  
  24.             // jump to the StartWiFi method that starts the WiFi and connect to the netowork
  25.             StartWiFi();
  26.  
  27.             // set the timer robot so it fires off a tick event
  28.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  29.  
  30.         }
  31.  
  32.         void timer_Tick(GT.Timer timer)
  33.         {
  34.             // collect data and instruct it to be sent to the spreadsheet
  35.             SendHTTPRequest("2000", "3000");
  36.         }
  37.  
  38.         void SendHTTPRequest(string entry_0, string entry_1)
  39.         {
  40.  
  41.             // construct the URL web link to include the data that we want to be logged
  42.             //WebClient.GetFromWeb("http://spreadsheets.google.com/formResponse?formkey=dEk2ZHVtVVNnQ1pCMW1LNTZWU0VQaUE6MQ&entry.0.single=" + entry_0 + "&entry.1.single=" + entry_1 + "&submit=Submit").ResponseReceived += new HttpRequest.ResponseHandler(Program_ResponseReceived);
  43.             //WebClient.GetFromWeb("http://docs.google.com/spreadsheet/formResponse?formkey=dEk2ZHVtVVNnQ1pCMW1LNTZWU0VQaUE6MQ&entry.0.single=" + entry_0 + "&entry.1.single=" + entry_1 + "&submit=Submit").ResponseReceived += new HttpRequest.ResponseHandler(Program_ResponseReceived);
  44.             WebClient.GetFromWeb("http://docs.google.com/spreadsheet/formResponse?formkey=dEk2ZHVtVVNnQ1pCMW1LNTZWU0VQaUE6MQ&entry.0.single=test&entry.1.single=testing&submit=Submit").ResponseReceived += new HttpRequest.ResponseHandler(Program_ResponseReceived);
  45.      
  46.         }
  47.  
  48.         void Program_ResponseReceived(HttpRequest sender, HttpResponse response)
  49.         {
  50.             if (response.StatusCode != "200")
  51.             {
  52.                 Debug.Print(response.StatusCode);
  53.             }
  54.             else
  55.             {
  56.                 // we recieved a 200 response which means that everything is ok
  57.                 Debug.Print("Data Logged");
  58.             }
  59.  
  60.         }
  61.  
  62.         void StartWiFi()
  63.         {
  64.             // these are the insturctions to connect to your home WiFi
  65.             wifi.UseDHCP();
  66.             Gadgeteer.Modules.GHIElectronics.WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
  67.             info.SSID = "network_name";
  68.             info.SecMode = WiFi_RS21.SecurityMode.WEP;
  69.             info.networkType = WiFi_RS21.NetworkType.AccessPoint;
  70.             wifi.Join(info, "network_password");
  71.             wifi.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown);
  72.             wifi.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp);
  73.         }
  74.  
  75.         void wifi_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
  76.         {
  77.             // tell everyone that the network isn't working
  78.             Debug.Print("network down: connecting....");
  79.             timer.Stop();
  80.         }
  81.  
  82.         void wifi_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
  83.         {
  84.             // tell everyone that the network is working
  85.             Debug.Print("network up");
  86.             Debug.Print(wifi.NetworkSettings.IPAddress);
  87.  
  88.             // send the first value to the spreadsheet
  89.             SendHTTPRequest("one","two");
  90.             // start the timer robot which will send new values every time it ticks
  91.             timer.Start();
  92.         }
  93.  
  94.        
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment