I have been using application Thingspeak for a while to post data. Suddenly it stopped working. After some debugging it seems the Netduino hangs when trying to connect the socket ( socket.connect(remoteEndPoint)). This only happens for api.thingspeak.com. If i try a local url or e.g. google.com the socket connection happens without any problems. Connecting to api.thingspeak.com from other devices ( POST test on my laptop ) works without problems. I have spend two days trying to figure out what could be wrong without results.
Thanks for picking up my problem. My Thingspeak account is still active and I can post data with a Google test app to POST a message. It is only the Netduino ( 2 PLUS ) which hangs on socket connect.
Are you using Netduino to connect to Thingspeak ? If yes, what code are you using to connect ?
Hi, I found some code examples for Thingspeak and implemented those on the NP2. A bit to my surprise this is working now so the problem is somehow solved though i still do not understand why my current code suddenly stopped working. My not working code is:
public static void POSTToThingspeak(string data, int connectTimeout)
{
string host = “api.thingspeak.com”; //Debug.Print(“Trying to send POST data to Thingsspeak server”);
IPEndPoint remoteEndPoint = new IPEndPoint(Dns.GetHostEntry(host).AddressList[0], 80);
try
{
Socket connection = new SocketConnectWithTimeOut(remoteEndPoint, connectTimeout, “tcp”).Connect();
SendThingspeakPOSTRequest(connection, data);
connection.Close(); //Debug.Print(“Ready sending POST data to Thingsspeak”);
}
catch (SocketException e)
{
Debug.Print("connection error for: " + remoteEndPoint.Address.ToString() + e.Message + e.ErrorCode.ToString());
if (e.ErrorCode == 10038) Debug.Print(“Socket Timeout error 10038”);
}
catch (SocketTimeoutException e)
{
Debug.Print("Socket Timeout error " + e.Message);
}
catch (Exception e)
{
Debug.Print("connection error for: " + remoteEndPoint.Address.ToString() + e.Message);
}