Noob--API help?



  • Hi,

    Loving this stuff! I'm ready to move on from basics and want to start more original work. Hence the need to dive into the API.

    Is there any guide, beyond the description on the API page as to how it all fits together?

    For example I'm trying to run my loop() code based on the state of the device in Vera. The hardware and program runs OK, and the node is talking to the GW. I'd really benefit from some kind of tutorial. Is there such a thing? I don't seem to grasp it all yet.

    Thanks in advance,
    --Steve



  • I solved my immediate concern by gleening off other sketches. It's another way to learn. Now I can control my loop by checking the state on the controller.

    Learning a little along the way. My question remains--is there a resource available beyond the API page that outlines the steps to embrace this awesome technology?

    Thanks,
    --Steve


  • Contest Winner

    @SteveO1234 said:

    I don't seem to grasp it all yet.

    building off of @SteveO1234 's good advice, well you can always ask directed questions here.

    @SteveO1234 said:

    I'm trying to run my loop() code based on the state of the device in Vera.

    try posting your code (between three back-ticks (accent like character below the tilde(~) character on my mac)

    typing this:

    Screen Shot 2015-05-19 at 10.37.34 PM.png

    looks like this:

    myCode
    is 
    here
    in this box
    

    when posted.



  • Thanks for the encouragement and help! So it seems as I need to create this message handler function that is referenced in the gw.begin().. And from that point any incoming messages are routed through the function?

    //
    void incomingMessage(const MyMessage &message)
    {
      if (message.isAck())
      {
        Serial.println("This is an ack from gateway");
      }
      if (message.type == V_LIGHT)
      {
        // Change relay state
        state = message.getBool();
        Serial.print ("State = ");
        Serial.print (state);
        // Store state in eeprom
        gw.saveState(ID, state);
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    //
    


  • Correct.


  • Contest Winner

    @SteveO1234 said:

    Thanks for the encouragement and help! So it seems as I need to create this message handler function that is referenced in the gw.begin().. And from that point any incoming messages are routed through the function?

    yup,

    So, you then have to manage a variable Vera-side that will then get polled from time to time by your Arduino. that request is bounced back as a message, that you handle as you noted above.

    Look at this example to see how you can manage the change of a stored variable in the Vera device... you merely need to update the stored variable in a change of state, and poll as frequently as you want to update.

    You can also send Vera html messages that in-turn would generate a message to a node in MySensors space.

    have fun!


Log in to reply
 

Suggested Topics

12
Online

11.2k
Users

11.1k
Topics

112.5k
Posts