Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using Microsoft.SPOT;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- namespace Gadgeteer_eMail_01
- {
- public partial class Program
- {
- // create a time based event robot to trigger repeated tasks
- GT.Timer timer = new GT.Timer(60000, GT.Timer.BehaviorType.RunContinuously);
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- // tell everyone that you have started
- Debug.Print("Program Started");
- // jump to the StartWiFi method that starts the WiFi and connect to the netowork
- StartWiFi();
- // set the timer robot so it fires off a tick event
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- }
- void timer_Tick(GT.Timer timer)
- {
- // collect data and instruct it to be sent to the spreadsheet
- SendHTTPRequest("2000", "3000");
- }
- void SendHTTPRequest(string entry_0, string entry_1)
- {
- // construct the URL web link to include the data that we want to be logged
- //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);
- //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);
- 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);
- }
- void Program_ResponseReceived(HttpRequest sender, HttpResponse response)
- {
- if (response.StatusCode != "200")
- {
- Debug.Print(response.StatusCode);
- }
- else
- {
- // we recieved a 200 response which means that everything is ok
- Debug.Print("Data Logged");
- }
- }
- void StartWiFi()
- {
- // these are the insturctions to connect to your home WiFi
- wifi.UseDHCP();
- Gadgeteer.Modules.GHIElectronics.WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
- info.SSID = "network_name";
- info.SecMode = WiFi_RS21.SecurityMode.WEP;
- info.networkType = WiFi_RS21.NetworkType.AccessPoint;
- wifi.Join(info, "network_password");
- wifi.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown);
- wifi.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp);
- }
- void wifi_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
- {
- // tell everyone that the network isn't working
- Debug.Print("network down: connecting....");
- timer.Stop();
- }
- void wifi_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
- {
- // tell everyone that the network is working
- Debug.Print("network up");
- Debug.Print(wifi.NetworkSettings.IPAddress);
- // send the first value to the spreadsheet
- SendHTTPRequest("one","two");
- // start the timer robot which will send new values every time it ticks
- timer.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment