Is it necessairy to use child id when requestin battery level or sketch name ... ?



  • Hello, I just learned how to request values from a node. When requesting a temperature or another sensor reading its logical to let the node respond via the child of the sensor in question. But what if requesting an internal message like sketch name (I_SKETCH_NAME) or battery level (I_BATTERY_LEVEL) or something like that. Then do you use a random child id or can it be done without? I just use something like child 100, but was just wondering if this is the right way to do it.


  • Mod

    @jimmy-loyens I am not very familiar with the internal messages, but sendBatteryLevel always sends with child id 255.



  • @mfalkvidd ok thanks. I originally had my nores setup to periodicly send battery level over child 0. Its more logical to have it send over child 255 then.

    You say normally on child 255 but isnt the user responsible to set this up in the receive function? Or am i missing something?

    Thanks


  • Mod

    @jimmy-loyens I don't know how receiving works. I have only seen battery level used when sending.



  • @jimmy-loyens said in Is it necessairy to use child id when requestin battery level or sketch name ... ?:

    me richiedere valori da un nodo. Quando si richiede una temperatura o un altro sensore leggendo la sua logica per consentire al nodo di rispondere tramite il figlio del sensore in questione. Ma cosa succede se si richiede un messaggio interno come il nome dello sch

    Hi, I'm bothering you for an info.
    You said that: "request a value at a node"
    And one thing that interests me, can you share how you do ?? Thanks for the time you want to dedicate ....



  • @sindrome73 Hi, shure you can bother me, happy to finaly help someone else (instead of asking help myself 😄 ).
    I dont really understand your quote since i dont speak spanish but i gues its a quote of my message.

    I just recently started playing with setting and requesting values so if someone (with more experiance) sees something wrong with what im writing here, feel free to correct me.

    Im using a mqtt gateway to communicate with my nodes. I have found i can use mqtt messages to set or clear a relay on a node withe the relay sketch (https://www.mysensors.org/build/relay) flashed to it by sending "mygateway1-in/nodeID/childID/Cmd/Ack/Type Payload" over MQTT. The "mygateway1-in" is the mqtt-topic for messages going to the node. (see this sketch for mqtt gateway https://www.mysensors.org/build/mqtt_gateway). The same should be possible using a serial gateway by sending "nodeID;childID;Cmd;Ack;Type;Payload" in the arduino serial monitor or any other terminal program (but i havent tried it with serial yet). Depending if payload is 1 or 0 the relay will turn on or off. You will notice in the relay sketch there is a function receive(). This is where the message to the node is interpreted and the state of the relay is set.

    The meaning of Cmd, Ack, Type and payload can be found here https://www.mysensors.org/download/serial_api_20. So when i want to turn the relay on on node 100 child 50 i actually send: "mygateway1-in/100/50/1/1/2 1", for turning it off i will send: "mygateway1-in/100/50/1/1/2 0". Notice in this case Cmd is 1 because we want to "SET" a value, and Type is 2 because it is a "binairy status". (see https://www.mysensors.org/download/serial_api_20). The same can be done for internal messages like requesting battery level or sketch name:

    Battery level => I_BATTERY_LEVEL => "mygateway1-in/100/50/3/1/1" => node returns battery level.
    Notice: Cmd=3 => internal message; Type=1 => I_BATTERY_LEVEL; Payload is empty => not setting anything

    Sketch name => I_SKETCH_NAME => "mygateway1-in/100/50/3/1/11" => node returns sketch name
    Notice: Cmd=3 => internal message; Type=11 => I_SKETCH_NAME; Payload is empty => not setting anything

    Same is true when requesting a sensor value, for example a temperature connected on child 12 of node 3:
    temperature => V_TEMP => "mygateway1-in/3/12/2/1/0" => node returns temperature
    Notice: Cmd=2 => Request; Type=0 => V_TEMP; Payload is empty => not setting anything

    Allso when setting a value other than for a relay, for example setting color of a RGB led on child 55 of node 47:
    rgb value => V_RGB => "mygateway1-in/47/55/1/1/40 0xffffff" => sets rgb ledcolour to white
    Notice: Cmd=1 => Set; Type=40 => V_RGB; Payload = 0xffffff => the value for r,g & b (in this case white)

    You can know wich Type value to use by looking in the sketch how the child is presented in present() function (S_HUM, S_TEMP, S_DOOR, ...) and looking up the appropreate V_value in the next table. (see https://www.mysensors.org/download/serial_api_20).

    Last remarque, the user (YOU) is responsible to write the code in the receive() function to handle incomming messages for the various types. You will notice in the relay sketch this is only done for V_STATUS because the sketch only has one type presented as S_BINARY. If your node has multiple children of various types you will have to expand your receive() function for any type you would like the node to receive messages from. If you make different functions for each type as you go allong and place these in the receive() function you should be able to re-use these functions in other sketches.

    I hope this helps, let me know how you get on
    Greets


Log in to reply
 

Suggested Topics

  • 1
  • 6
  • 5
  • 10
  • 2
  • 1

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts