Setting parameters in nodes



  • I'd like to have some way to set parameters/settings in nodes.
    For example, my chicken shed is one Mysensors node that combines multiple sensors and actuators. I'd like to be able to update settings like sunset, sunrise, lux treshold, light (de-)activation time, etc without having to recompile the arduino sketch.
    I prefer to have the basic logic in the sensor node, not in the controller so that the shed continues to function even when the controller is down.
    I'm building my own micro-services based controller that will be able to handle settings/parameters but need some mechanism to tranverse the MySensors radio path.



  • This.
    It would be great if able to set wake-up periods and other parameters in the controller software and save it to the node when it wakes up. Like z-wave does. You can change parameters and save them. The node wakes up, sends the data as it should and looks if there is any config updates from the controller. If there is, it saves them and goes back to sleep. 🙂


  • Admin

    @stefaanv

    You could use the VAR1-5 as a containers for your configuration. Then either request it or push it to your node.


  • Admin

    @NiklasO

    That's the idea behind the new smartSleep function, which allows controllers to buffer data and send it when node wakes up .



  • @hek
    Ok, thanks. Just started using MySensors, learning as I go. 😉



  • @hek
    VAR1-5 comes very close but is limited to 5 variables only.
    It would be better to have a generic key/value pair mechanism.
    Parameters/settings can be anything like

    • Setpoints
    • Program cycle times
    • Date/time settings
    • Process parameters (motor runtime, how time to wait before going into error mode, ...)
    • Booleans that alter program execution behaviour
      Ideally these can be pushed by the controller and requested by the node.

  • Hardware Contributor

    I'm also using custom parameters in some fw so i can change settings on the fly without reflash.
    Limited to 5vars?? I'm not sure, i can't check right now, but i think i'm using a sketch where i have for instance two VAR4 at same time...as it's not same child id should be ok? i may be wrong i need to check. Or perhaps V_CUSTOM could do the trick



  • I think the purpose of the V_VAR is interpreted in different ways. So it's sometimes hard to use V_VAR as configuration parameters.

    E.g. In Domoticz V_VAR is used to store and restore node variables. They are stored in the Domoticz database when send by the node. The node can retrieve a previous stored value from the database. There is no easy way to set the variables. So V_VAR kan be used as remote permanent memory.

    It would be nice if there was an implicit specification for configuration parameters.
    A possible option could be:

    • Extra message types for parameters:
      Type: set_parameter, Number: 5, Comment: Set configuration parameter.
      Type: req_parameter, Number: 6, Comment: Request configuration parameter.
    • Extra subtypes for parameters:
      Type: P_SEND_RETRIEVE, Value:0, Comment: Trigger the node to send or retrieve all configuration parameters. 0=Retrieve, 1=Send.
      Type: P_PAR<number>, Value: <number>, Comment: Configuration parameter <number>
      The values of the parameters can be any type, like stefaanv suggests.
    • Add functions:
      request_parameter, to handle retrieving parameters: void request_parameter (uint8_t childSensorId, uint8_t configParam, uint8_t destination);
      send_parameter, to handle sending paramters: bool send_parameter (MyMessage &msg, bool ack);

    The idea behind P_SEND_RETRIEVE:
    If a node receives a P_SEND_RETRIEVE message from the gateway with value 0, a routine can be triggered to request all configuration parameters one by one, using function request_parameter.
    If a node receives a P_SEND_RETRIEVE message from the gateway with value 1, a routine can be triggered to send all configuration parameters one by one, using function send_parameter.



  • I got this one solved for openHab2, but I guess the same trick can also work with other controllers.
    In openhab, activate the mqtt-eventbus bridge that copies all events on the eventbus to an mqtt broker of your choice.

    The mqtt.cfg configuration file (example)

    mosquitto.url=tcp://localhost:1883
    mosquitto.clientId=openhab
    mosquitto.retain=true
    mosquitto.async=false
    

    The mqtt-eventbus.cfg configuration file (example)

    broker=mosquitto
    statePublishTopic=openHAB/out/${item}/state
    stateSubscribeTopic=openHAB/in/${item}/state
    commandSubscribeTopic=openHAB/in/${item}/command
    

    In the openhab .things configuration file, add a text element elements for the node

    ...
    text         test_text   [ nodeId="4", childId="200"] 
    customSensor gasMeter    [ nodeId="4", childId="1"]
    ...
    

    In the .items configuration file, add the text element as well

    String test_text           "text"         <text> {channel="mysensors:text:gateway:test_text:text"}
    Number gasMeter_teller     "Counter"      <var1> {channel="mysensors:customSensor:gateway:gasMeter:var1"}
    Number gasMeter_pulsLengte "Pulse Lengte" <var2> {channel="mysensors:customSensor:gateway:gasMeter:var2"}
    

    On the node, define an extra S_INFO/V_TEXT child sensor. The below code example parses incoming instructions (in the receive() function).

    #define CHILD_ID_TEXT 200 
    MyMessage textMsg(CHILD_ID_TEXT, V_TEXT);
    
    void presentation()
    {
    	...
    	present(CHILD_ID_TEXT, S_INFO);
    	...
    }
    
    ...
    void receive(const MyMessage &message)
    {
    	if (message.type == V_VAR1)
    	{
    		pulseCounter = message.getLong(); // Update the main counter value at node startup or when updating the value in openhab UI
    	}
    
    	if (message.type == V_TEXT)
    	{
    		//this code could be more professional, just doing it quick and dirty for now
    		String all = message.data;
    		int equalSignPosition = all.indexOf('=');
    		if (equalSignPosition < 0) return;
    		String key = all.substring(0, equalSignPosition);
    		String value = all.substring(equalSignPosition +1, all.length());
    
    		if (key == "debouncePeriod")
    		{
    			int dbPvalue = value.toInt();
    			if (dbPvalue > 5 && dbPvalue < 5000) {
    				debouncePeriod = dbPvalue;
    				SendParameter("Debounce period",debouncePeriod);
    			}
    		}
    		if (key == "timeBeforeSleep")
    		{
    			long tBFSvalue = value.toInt();
    
    			if (tBFSvalue > 1000 && tBFSvalue < 300000) {
    				timeBeforeSleep = tBFSvalue;
    				SendParameter("Time before sleep", timeBeforeSleep);
    			}
    		}
    		if (key == "info")
    		{
    			Serial.print("Sending information");
    			SendParameter("debouncePeriod", debouncePeriod);
    			SendParameter("timeBeforeSleep", timeBeforeSleep);
    			SendParameter("pulseCounter", pulseCounter);
    		}
    	}
    }
    
    void SendParameter(char* parameterName, unsigned long variable)
    {
    	char buffer[30];
    	sprintf(buffer, "%s->%lu", parameterName, variable);
    	Serial.println(buffer);
    	send(textMsg.set(buffer));
    }
    ...
    

    Now parameters can be changed by sending mqtt messages to openhab which will forward the instructions to the node. Feedback is provided in the reverse way for every parameter change.
    For example, to change the debounce period, send an MQTT message with topic= openHAB/in/test_text/command and data=debouncePeriod=<value>. The feedback is provided on topic=openHAB/out/test_text/command with data=debouncePeriod-><value>.
    To get an overview of the parameters, send info=. One message is returned for every parameter and one for the current meter counter value.



  • @stefaanv I like your method of sending config data to a sensor. I have tried your example but I don't receive any data on my sensor. Will you please clarify the following:

    1. You gave and example of the mqtt.cfg configuration file:
    mosquitto.url=tcp://localhost:1883
    mosquitto.clientId=openhab
    mosquitto.retain=true
    mosquitto.async=false
    

    What does the "mosquitto.clientId=openhab" mean? Is the "openhab" a name that I should have used somewhere in my OpenHab setup?

    1. Your mqtt-eventbus.cfg example:
    broker=mosquitto
    statePublishTopic=openHAB/out/${item}/state
    stateSubscribeTopic=openHAB/in/${item}/state
    commandSubscribeTopic=openHAB/in/${item}/command
    
    • Is the "broker =mosquitto" a name that I should have defined somewhere?
    • Later on in your example you mention "The feedback is provided on topic=openHAB/out/test_text/command ..." but the "openHAB/out/test_text/command" is not indicated in the mqtt-eventbus.cfg file. Is that correct?
    1. I have installed the latest OpenHab and I use the PaperUI to configure my Things. The PaperUI has detected my sensor as "mysensors:text:gateway:text_1_202:text" and I don't know where I can edit the name of the Thing. I have added the item in .items config file as
    String test_text "text" <text> {channel="mysensors:text:gateway:text_1_202:text"}
    
    1. I have installed mosquitto and I can subscribe and publish with the following commands:
      In one terminal I subscribe with
    mosquitto_sub -h 127.0.0.1 -i openhab -t openHAB/in/text_1_202/command
    

    and in another terminal I publish using:

    mosquitto_pub -h 127.0.0.1 -i openhab -t openHAB/in/test_1_202/command -m info=
    

    On the "subscribe" terminal I do get the "info=" message, but I don't receive anything on the node.
    I'm not sure if my publish channel is correct because my node name is different than yours.

    How can I check that OpenHab do receive the MQTT command?
    Can you spot any other setup issue that I might have?



  • @FredRoot
    To answer your questions

    1. "mosquitto.clientId=openhab"

    I got my inspiration for setting up the eventbus-to-mqtt bridge from this website
    Basically, in the mqtt.cfg file you're defining which mqtt broker openhab must talk to. Afaik you can freely chose the broker name, but I wasn't very adventurous and simply copied the example configuration.

    You DO have to install an MQTT broker separate from openhab. Mosquitto is the most common one.
    The clientID setting can be about anything, it is like a call name for the broker to identify its counter parts. the clientID is often auto-generated by using random numbers. You can use anything as long as this same ID is not used by anyone else on the same broker (which is a problem in what you're doing further down).

    2.

    In broker=mosquitto the second part must be the same like the part before the dot in mosquitto.clientId=openhab. It is an identification for the MQTT broker that you're using in the different openhab configuration files.

    topic=openHAB/out/test_text/command ... is commandSubscribeTopic=openHAB/in/${item}/command where ${item} was replaced with the name of the item which in this case is test_text. Openhab will do the insertion of the item names for you.

    3. & 4.

    That look OK.
    Best thing to do is to install a program like MQTT-Spy. It allows you to see all the messages being processed by the MQTT broker and send messages in a convenient way. Trying to do this from the Linux CLI is overly courageous.
    Anyway, you should definately not use the -i openhab switch with mosquitto_sub or _pub. You need to use a different clientId than the one openhab is using. You're not trying to trick mosquitto in believing you're openhab. Instead you're trying to talk to openhab through the MQTT boker.

    An interesting one is to enable debug logging for the MySensors binding on the Karaf interface. That way you can see what openhab is sending to your MySensors gateway.

    Here's how you do that

    • Open an ssh connection to your openhab server
    • Type ssh -p 8101 openhab@localhost. The password will probably be habopen. This is the Karaf CLI

    Some usefull Karaf commands

    • log:tail will show the Openhab logs as they come in. You can pipe this command with grep if you're looking for something specific.
    • Use log:set xxxxx to adapt the logging level
    • smarthome:things list to see all your things
    • smarthome:things list to see all your things

    So to see what openhab is sending to the MySensors gateway use these commands

    log.set DEBUG org.openhab.binding.mysensors
    log.tail
    

    Now if you send an MQTT configuration message to openhab using MQTT_Spy, you should see the message being passed to the mysensor gateway. This will help you debug the setup.

    Stefaan



  • @stefaanv Thank you for this detailed feedback.
    I will try your suggestions this afternoon.



  • @stefaanv I have installed MQTT-Spy and I can publish on the "openHAB/in/test_text/command" topic and OpenHub does forward the message to my node 😀 ,but I receive the reply data in the "openHAB/out/test_text/state" topic. Besides the expected data is there also a lot of other data from my other sensors as well. I have changed my mqtt-eventbus.cfg to :

    broker=mosquitto
    statePublishTopic=openHAB/out/test_text/state
    stateSubscribeTopic=openHAB/in/test_text/state
    commandSubscribeTopic=openHAB/in/${item}/command
    

    I have hoped that it will limit the amount of data. This did helped a bit, but see all the additional data below. I receive this data even if the sensor is switched off. The debouncePeriod->0 ,timeBeforeSleep->0 and pulseCounter->0 is only received when I transmit the command via MQTT-SPY but the set is repeated every second.

    openHAB/out/test_text/state debouncePeriod->0
    openHAB/out/test_text/state 0.0
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 341
    openHAB/out/test_text/state 341
    openHAB/out/test_text/state timeBeforeSleep->0
    openHAB/out/test_text/state 2017-07-20T19:20:22
    openHAB/out/test_text/state 2017-07-20T19:20:22
    openHAB/out/test_text/state pulseCounter->0
    openHAB/out/test_text/state 2017-07-20T19:20:22
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 99
    openHAB/out/test_text/state 99
    openHAB/out/test_text/state 581
    openHAB/out/test_text/state 581
    openHAB/out/test_text/state 32.3
    openHAB/out/test_text/state 32.3
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 63.0
    openHAB/out/test_text/state 63.0
    openHAB/out/test_text/state 461
    openHAB/out/test_text/state 461
    openHAB/out/test_text/state 91.7
    openHAB/out/test_text/state 91.7
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 100.0
    openHAB/out/test_text/state 100.0
    openHAB/out/test_text/state 5078
    openHAB/out/test_text/state 5078
    openHAB/out/test_text/state 37.0
    openHAB/out/test_text/state 37.0
    openHAB/out/test_text/state 8.3
    openHAB/out/test_text/state 8.3
    openHAB/out/test_text/state 0.0
    openHAB/out/test_text/state 0.0
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 341
    openHAB/out/test_text/state 341
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 99
    openHAB/out/test_text/state 99
    openHAB/out/test_text/state 581
    openHAB/out/test_text/state 581
    openHAB/out/test_text/state 19.7
    openHAB/out/test_text/state 19.7
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 63.0
    openHAB/out/test_text/state 63.0
    openHAB/out/test_text/state 461
    openHAB/out/test_text/state 461
    openHAB/out/test_text/state 91.7
    openHAB/out/test_text/state 91.7
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state Undefined
    openHAB/out/test_text/state 100.0
    openHAB/out/test_text/state 100.0
    openHAB/out/test_text/state 5078
    openHAB/out/test_text/state 5078
    openHAB/out/test_text/state 37.0
    openHAB/out/test_text/state 37.0
    openHAB/out/test_text/state 8.3
    
    

    Any idea how I can stop this data from being transmitted via mqtt?



  • @FredRoot
    Your mqtt-eventbus.cfg configuration should look like this

    broker=mosquitto
    statePublishTopic=openHAB/out/${item}/state
    stateSubscribeTopic=openHAB/in/${item}/state
    commandSubscribeTopic=openHAB/in/${item}/command
    

Log in to reply
 

Suggested Topics

20
Online

11.2k
Users

11.1k
Topics

112.5k
Posts