Error while compiling automation script

8 years 7 months ago #2241 by vickeyhort
Hi.

I am trying to make home automation setup which involves lot of sensor nodes. But I am facing a problem in automation right now.

I want to automate lights turn on function based on door reed sensor and pir sensor but only in low light conditions based on LDR sensor attached to one node only. I want to update LDR value on all nodes without attaching LDR sensor on every node. Later I'll adopt the same technique for Electricity sensor.

Here is the arduino sketch which I have adopted for testing purpose

#include <MySensor.h>
#include <SPI.h>

#define CHILD_ID_LIGHT_STATUS 0
#define CHILD_ID_LIGH_LEVEL 1
MySensor gw;
MyMessage msgLightSt(CHILD_ID_LIGHT_STATUS, V_STATUS);
MyMessage msgLightLv(CHILD_ID_LIGH_LEVEL, V_LIGHT_LEVEL);
unsigned long LastSent = 0;
unsigned long Now = 0;
int LightLevel = 0;

void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, false);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Fetch Test", "1.0");
gw.present(CHILD_ID_LIGHT_STATUS, S_LIGHT);
gw.present(CHILD_ID_LIGH_LEVEL, S_LIGHT_LEVEL);
}

void loop()
{
// Alway process incoming messages whenever possible
gw.process();
Now = millis();
if ((Now - LastSent) > 5000) {
gw.send(msgLightSt.set(0));
}
}

void incomingMessage(const MyMessage &message) {
if (message.type==V_LIGHT_LEVEL) {
LightLevel = (100 - (atoi ( message.data )));
Serial.print("Light conditions are ");
Serial.print(LightLevel);
Serial.print(" %");
Serial.println();
}
}


"CHILD_ID_LIGHT_STATUS" is used to send command to controller for light conditions and "CHILD_ID_LIGH_LEVEL" will store the percent light level.

when a node send this "0" status for "CHILD_ID_LIGHT_STATUS" to controller, Controller will update "CHILD_ID_LIGH_LEVEL". But I am facing problem with automation script on controller side. Here is the piece of code I am using in automation,

/*
This code is running one time when program is enabled
*/
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{

// filter digital switch - change module address
if (m.Domain == Domains.MYSENSORS && m.Address == "N1S0" && p.Property == "Sensor.DigitalValue"){
// filter when switch on event
if (p.Value == "0")
{ ModuleParameter pVal = ModuleHelper.GetProperty(Domains.MYSENSORS, "N0S0", "Sensor.LightLevel");
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N1S1", "Sensor.LightLevel", "pVal");
}
}
});
}

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


Above code is yielding following error;

Errors:

Error CS1643 in line 6 column 36, Not all code paths return a value in anonymous method of type `System.Func'
Program disabled, fix errors first.


Can anyone help me to fix this problem? I have tried a lot of things mentioned in forum but nothing is working for me. Please help

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

8 years 7 months ago - 8 years 7 months ago #2242 by vickeyhort
I want to add up couple of things ;

The arduino sketch i have attached is just for test purpose, i'll change it later when the things will start working correctly.

I am using sleep function in sensor node to reduce battery consumption, Sensor node with LDR attached, will update light level every 30 minutes, that's why It will not be possible to fetch the LDR value directly from sensor node. I want to return the LDR value updated on controller side anytime prior to the request made by any other sensor node. That's why I want to use automation function on EasyIOT.

My main questions are;

1) How to make request for a sensor value updated already on controller server

2) How to make a variable in the automation script which will store that sensor value

3) which (variable) will be used to update or send or set the value on other node when requested.

Thanks for reading my very long post. Sorry!!

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

8 years 7 months ago #2243 by NightOne
Hi there,
I like the idea of your project and I would like to suggest that you make the sensor nodes just be sensor node and leave the logic and automation stuff to the EasyIOT server, so for example the light sensor has no logic it just wakes up ever 30 min takes a sensor reading, and updates the EasyIOT server. The you use that value on the server and write automation scipts based on that.

Most of the information you need about calling the values are on this page:
iot-playground.com/2-uncategorised/32-ea...-automation-part-iii

ModuleHelper: is use to get or set values on the server but does not trigger an event, so you use it to create nested if statements where an event is subject to the value retireved from the ModuleHelper

EventHelper: is used in automation to watch for changed values and trigger an event (see examples on link)

DriverHelper: is used to control values or commands, there are three controls. ControlOn, ControlOff and Control level you use these when you want to switch something on or off or set a sensor value.

EasyIOT server also has a REST API at xx.xx.xx.xx/Api/EasyIoT/Config/Module/List which is in json so you can do value calls from other systems and senors if you need.

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

8 years 7 months ago #2244 by vickeyhort
Thank you NightOne for your quick response.

As I have enough experience with arduino programming and I have no experience with programming used here in automation script. The information you provide gone over my head. I am sorry. Can you help me to correct the code I have written and post in my first post?

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

8 years 7 months ago #2245 by vickeyhort
I have tried you suggestions, here is the code

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
// filter digital switch - change module address
if (m.Domain == Domains.MYSENSORS && m.Address == "N1S0" && p.Property == "Sensor.DigitalValue"){
ModuleParameter p = ModuleHelper.GetProperty(Domains.MYSENSORS, "N0S0", "Sensor.LightLevel");
if (p > 50) {
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N10S0", "Sensor.DigitalValue", "1");
}
}
return true;
});
}


It gives following error

Errors:

Error CS0136 in line 7 column 23, A local variable named `p' cannot be declared in this scope because it would give a different meaning to `p', which is already used in a `parent or current' scope to denote something else
Program disabled, fix errors first.

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

8 years 7 months ago #2246 by NightOne
in the first if statement you already declare p... if you look close it says p.Property...so you cant declare p again.... change ModuleParameter p to something like ModuleParameter n and then (n > 50)

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

Time to create page: 0.303 seconds

Forum latest

  • No posts to display.