First I want to thank you for what you are doing, without you I couldn't do anything. I tried what you said and I got the line in the console it's ok bu the problem is my code for the GET request, it doesn't do anything. I can't manage to get the WebRequest Class working.
Hi,
Can you share a little bit more about your final goal?
What is the purpose of the GET message?
Is it for an intranet or internet server?
Fix URL or dynamic one?
If you do the GET via browser, how long will take to get the answer back?
The goal is to be able to send an SMS or tweet something thanks to uzzy.me a service developed by a friend, it's a fix URL. It takes maybe 100ms to get the answer back.
The code compiles and I'm writing to the console both before and after the code execution which also works. However no http socket is opened towards the server I'm trying to connect to.
I've checked the access log of that server but there's no input from this IP. I've done a netstat while turning on the program but there's no socket opening as far as I can see.
When I do a wget to the same URL it works.
I've tried many code examples by now but all are the same. The last one I tried is the one in this thread.
public void Setup()
{
System.Net.WebRequest.Create("http://192.168.0.10/index.shtml");
}
I am new to developement so this might be wrong advice but from what I know about EasyIOT the code sample you gave can not run as when its in public void Setup() it needs an event to happen to trigger....meaning you need to have something like this.
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
if (m.Domain == Domain.VIRTUAL && m.Address == "N5S0" && p.Property == "Sensor.Temperature" && p.Value=="15")
System.Net.WebRequest.Create("http://192.168.0.10/index.shtml");
}
This means when the value of sensor N5S0 equals 15 then it triggers the create the web request.
I have to assume that you want to call the web reguest when something happens rather then at a specific time meaning it must be controlled but the eventhelper, if you want to make the code run without an event is to put it in public void Run() then add a crontab value to get it to run like * * * * * makes it run every minute, after running into trouble with crontab jobs I can recommend that you make a NEW automation script and not change an old one.
Thank you for your help NightOne. I do have an event handler, I just left it out in my post since I thought the code should be executed every time you enable the application manually. But maybe I was wrong?
Anyways, this morning it started to work all by itself.. All I did last night was to shut easyiot down and start it as a service before going to sleep.
So for anyone who is interested this is what my working code looks like:
/*
This code is running one time when program is enabled
*/
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
// Mailbox open
if (m.Domain == Domains.MYSENSORS && m.Address == "N8S3" && p.Property == "Sensor.DoorWindow")
SendTrigger();
return true;
});
}
/*
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
*/
public void Run()
{
}
private void SendTrigger()
{
string msgURL = "http://192.168.0.10/axis-cgi/io/virtualinput.cgi?action=6:/";
Uri address = new Uri(msgURL);
Console.WriteLine("Send request to camera..");
try
{
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(address) as System.Net.HttpWebRequest;
request.Method = "GET";
request.ContentType = "text/xml";
using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
{
}
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
}
// return 0;
}