GET request on automation

9 years 2 months ago #2131 by eliobou
Hi,
I want to modify the water leak SMS notification code to send a GET request to a server when a sensor is trigered. Is it possible ? I want something like this :
/*
  This code is running one time when program is enabled
*/
public void Setup()
{		
    EventHelper.ModuleChangedHandler((o, m, p) =>
    {    
  	  // bathroom alarm
      if (m.Domain == Domains.MYSENSORS && m.Address == "N8S0" && p.Property == "Sensor.Leak" && p.Value == "1")
      	DO A GET REQUEST
      
      // living room
      if (m.Domain == Domains.MYSENSORS && m.Address == "N3S0" && p.Property == "Sensor.Leak" && p.Value == "1")
        DO A GET REQUEST
        
      return true;
    });
}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}

Thank you,
Eliobou

Please Log in or Create an account to join the conversation.

9 years 2 months ago #2134 by bit
Replied by bit on topic GET request on automation
easyiot don't provide this feature. you need to handle it with mono c#.

https://msdn.microsoft.com/en-us/library/456dfw4f%28v=vs.110%29.aspx

I'm sorry for my poor english.

Please Log in or Create an account to join the conversation.

9 years 2 months ago #2136 by eliobou
Replied by eliobou on topic GET request on automation
I'm new to C# I don't know anything about that, I came to this code but I keep getting this error :

Error CS1519 in line 1 column 9, Unexpected symbol `using' in class, struct, or interface member declaration
Error CS1519 in line 1 column 17, Unexpected symbol `;' in class, struct, or interface member declaration
Error CS1519 in line 2 column 16, Unexpected symbol `;' in class, struct, or interface member declaration
Error CS1519 in line 3 column 17, Unexpected symbol `;' in class, struct, or interface member declaration
Error CS1519 in line 4 column 18, Unexpected symbol `;' in class, struct, or interface member declaration

Can you help me ?
using System;
using System.IO;
using System.Net;
using System.Text;

/*
  This code is running one time when program is enabled
*/
public void Setup()
{   
    EventHelper.ModuleChangedHandler((o, m, p) =>
    {    
      if (m.Domain == Domains.VIRTUAL && m.Address == "N1S0" && p.Property == "Sensor.DigitalValue" && p.Value == "1") {
        WebRequest request = WebRequest.Create("http://website.com");
      }
    });
}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}

Please Log in or Create an account to join the conversation.

9 years 2 months ago #2139 by hjfabius
Replied by hjfabius on topic GET request on automation
Try removing your 4 first lines.
If you have an error on the webrequest line, add the namespace to the type.
Sorry but i'm out and i cannot test.

Please Log in or Create an account to join the conversation.

9 years 2 months ago #2140 by eliobou
Replied by eliobou on topic GET request on automation
I already tried to remove the first 4 lines but I keep getting an error about the web request line. I don't know what you want to say by "add the namespace to the type.", as I say I'm a newbie about C# could you explain precisely what that mean or modify my code so I could see what that mean.
Thank you

Please Log in or Create an account to join the conversation.

9 years 2 months ago #2153 by hjfabius
Replied by hjfabius on topic GET request on automation
Try with something like
System.Net.WebRequest request = System.Net.WebRequest.Create("http://website.com");

Please Log in or Create an account to join the conversation.

Time to create page: 0.265 seconds

Forum latest

  • No posts to display.