Hello I’m having a problem with the following code, I run FEZ Connect with panda2 and after a while the board just hangs and is not available even through local address anymore:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using System.Text;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
namespace FEZ_Panda_II_Application8
{
public class Program
{
static Thread thread;
static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.An4, false);
static bool running;
//static
public static void MainLoop()
{
while (running)
{
HttpWebRequest request = HttpWebRequest.Create("http://myftpsite/index.php") as HttpWebRequest;
//request.KeepAlive = true;
WebResponse resp = null;
try
{
resp = request.GetResponse();
}
catch (Exception e)
{
Debug.Print("Exception in HttpWebRequest.GetResponse(): " + e.ToString());
}
Thread.Sleep(6000000);
}
}
public static void Main()
{
byte[] ip = { 192, 168, 1, 176 };
byte[] subnet = { 255, 255, 255, 0 };
byte[] gateway = { 192, 168, 1, 254 };
byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };
WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
NetworkInterface.EnableStaticDns(gateway);
// start server
HttpListener listener = new HttpListener("http", 80);
listener.Start();
// Begin calling ddns
running = true;
thread = new Thread(MainLoop);
thread.Priority = ThreadPriority.Highest;
thread.Start();
while (true)
{
HttpListenerResponse response = null;
HttpListenerContext context = null;
try
{
context = listener.GetContext();
response = context.Response;
// The button is pressed
if (context.Request.HttpMethod == "POST")
{
led.Write(true);
Thread.Sleep(1000);
led.Write(false);
}
// Sends response
response.StatusCode = (int)HttpStatusCode.OK;
byte[] HTML = Encoding.UTF8.GetBytes(
"<head>" +
//"<META HTTP-EQUIV=\"refresh\" CONTENT=\"120\">" +
"</head>" +
"<html><body>" +
"<h1>Doors</h1>" +
"<form action=\"\" method=\"post\">" +
"<input type=\"submit\" value=\"Open/Close\">" +
"</form>" +
"</body></html>");
response.ContentType = "text/html";
response.OutputStream.Write(HTML, 0, HTML.Length);
response.Close();
}
catch
{
if (context != null)
{
context.Close();
}
}
}
}
}
}
So the problem is within tread calling every 6000 seconds. I know this is wrong but what I’m trying to do is my own implementation of ddns service since nothing else is working with my poor router. So what I’m trying to do is to HTTP/GET a document on my ftp server every once a while. Then I have simple php script that stores the ip of the board so I can call the board with domain I have registered. (I’m not caling it once a minute since the firewall on my ftp server obviusly blocks it after 15 min).
So should I go and try with a timer to call every like 3600 sec or is that actauly the same as above?.Does anyone with more experience have better idea how to it?.
Would password protect with javascript be ok or should I add another input field for password?
And one more thing. I’m running the board with 9v through vin ports and at the same time powering transistor BC547 with the same power supply (9v 1000ma). I was reading that Fez Connect should be power from 6-7,5 V becouse it might overheat the onboard regulators. Is it ok if I power it with 9v?