Hi
I am a newbie trying to just update my switch state to Thingspeak,but each time i run my code,the program throws a System.Net.WebException on the GetRequestStream() which is going on happening.Below is my code:
///Authored by-: Sambeet Panigrahi
///Dated on-:10th January 2015
/*This program updates the Netduino Plus switch state to Thingspeak*/
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 System.Text;
using System.IO;
namespace LED__control_Thingspeak
{
public class Program
{
public static void Main()
{
var SwitchPort = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.
Disabled); //Open the switchport
bool onned = SwitchPort.Read();//Read the status of switchport
if (onned)
{
update_thingspeak("30");
}
else
{
update_thingspeak("60");
}
}//Main ends
static void update_thingspeak(string value)
{
//Create a http response object
WebRequest request = HttpWebRequest.Create("https://api.thingspeak.com/update");
//Setting the request method
request.Method = "POST";
//The data to be sent
string data = "api_key=" + "T5Q1Y9QBY1TULCBG" + "&field1=" + value;
//Creating the byte array
byte[] bytearray = Encoding.UTF8.GetBytes(data);
//Setting the MIME
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytearray.Length;
//Opening the datastream
Stream datastream = request.GetRequestStream();
//Writing to the datastream
datastream.Write(bytearray, 0, bytearray.Length);
//Closing the stream
datastream.Close();
//Obtaining a response
WebResponse response = request.GetResponse();//Creating a response
datastream = response.GetResponseStream();//Getting the response stream
StreamReader reader = new StreamReader(datastream);// Read the content.
string responseFromServer = reader.ReadToEnd();// Display the content.
Debug.Print(responseFromServer);
}//update_thingspeak ends
}//class program ends
}//namespace ends
Can someone help me? I am a little out of time.