Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
B

Baran

@Baran
About
Posts
30
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • My Loops are out of sync.
    B Baran

    Greetings,

    The following sketch is a variation of one where I simply allowed all eight child sensors to be read and serial printed. I am now working on parsing the data and I know I have loop issues but I am too close to see my own issues. What I would expect this to do is, upon requesting a transmission from a node, print the Node, command, and payload eight times but it only catches the first of eight sensor's worth of data. Would someone suggest a re-placement of my loops in order to realize this?

    Thank you to all - Baran

    /*
     * Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
     * 
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     * 
     * DESCRIPTION
     * The ArduinoGateway prints data received from sensors on the serial link. 
     * The gateway accepts input on seral which will be sent out on radio network.
     *
     * The GW code is designed for Arduino Nano 328p / 16MHz
     */
    
    #include <SPI.h>  
    #include <MySensor.h>  
    #include <MyGateway.h>  
    #include <stdarg.h>
    MySensor gw();
    MyGateway gw(DEFAULT_CE_PIN, DEFAULT_CS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN,  6, 5, 4);  //  I would like to simplify this line but I do not know what to put here.  
    //No longer using inclusion mode or ce/cs
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    boolean commandComplete = false;  // whether the string is complete
    
    void setup()  
    { 
      gw.begin();
    }
    
    void loop()  
    { 
      gw.processRadioMessage();   
      if (commandComplete) {
        // A command wass issued from serial interface
        // We will now try to send it to the actuator
        gw.parseAndSend(inputString);
        commandComplete = false;  
        inputPos = 0;  //  I do not understand how this was ever incremented.
      }
    }
    
    
    /*
      SerialEvent occurs whenever a new data comes in the
     hardware serial RX.  This routine is run between each
     time loop() runs, so using delay inside loop can delay
     response.  Multiple bytes of data may be available.
     */
    void serialEvent() {
      while (Serial.available()) {
        for (int i = 0; i<8; i++){
         // look for the next valid integer in the incoming serial stream:
        int node = Serial.parseInt(); 
        // do it again, but throw it away:
        int w = Serial.parseInt(); 
        // do it again, but throw it away:
        int x = Serial.parseInt(); 
        // do it again, but throw it away:    
        int y = Serial.parseInt(); 
        // do it again, this is the Payload:
        int z = Serial.parseInt(); 
        // do it again, this is the current reading:
        int current = Serial.parseInt();
    
          // print the node and payload
          Serial.print("    The Node is :");
          Serial.print(node);
          Serial.print("    The Command is :");
          Serial.print(z);
          Serial.print("    The Payload is :");
          Serial.println(current);
          i = i+1;
        }
        }   
      }
    
    Troubleshooting

  • Close but no cigar . . .
    B Baran

    Good Day Bulldog,

    The code I used is the example you gave two days ago. Perhaps it needs some supporting code to actually operate but I was unable to even get it to compile. I have all the basic libraries in place so I am at a lose as to why I cannot compile the code you submitted. Any suggestions?

    Respectfully - Baran

    Troubleshooting

  • Controller Code that Demonstrates Integer Parsing
    B Baran

    @BulldogLowell said:

    char myString[23] = "1;0;1;0;17;354"; // this is a C string, not String class...
    /or like this: char myString = "1;0;1;0;17;354"; for example */

    Hi Bulldog,

    Could you explain the sttement (above)? I understand everything else about the code you posted except this. I think the "23" means you are allowing 23 spaces for the information but I do not understand the right side of the "=" sign. This is something like what might come through but why am I defining the payload? It could be from 20 to 1020 nd I do not understand the code above. Would you explain what this line is about and how the information in quotes relates to the variables being read in real time?

    Respectfully - Baran

    Controllers

  • Close but no cigar . . .
    B Baran

    Hi Bulldog,

    I hope you see this post. I like the way that you incorporated the switch statement into this example but I cannot quite get it to compile. I have included myGateway and mySensor libraries but I still have an error compiling and the error code (in red) looks like this:

    MySensors\MyGateway.cpp.o: In function MyGateway::parseAndSend(char*)': C:\Users\Baran\Documents\Arduino\libraries\MySensors/MyGateway.cpp:128: multiple definition of MyGateway::parseAndSend(char*)'
    sketch_may20a.cpp.o:C:\Program Files (x86)\Arduino/sketch_may20a.ino:6: first defined here
    core.a(main.cpp.o): In function main': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:40: undefined reference to setup'
    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:43: undefined reference to `loop'

    • list item

    If this makes any sense to you (or anyone) and you can tell me what I am forgetting in order to successfully compile (not necessarily run) this portion of code (given by Bulldog above), please enlighten me.

    Respectfully - Baran

    Troubleshooting

  • Close but no cigar . . .
    B Baran

    Hi Again Bulldog,

    For whatever reason, your code example did not show before I wrote that last post. Thank you for the clarity that you have brought, as well as your patience. This example, along with the radically different approach that you suggested in Troubleshooting, gives me plenty to chew on.

    Respectfully - Baran

    Troubleshooting

  • Close but no cigar . . .
    B Baran

    I would really rather not re-invent this wheel . . . I just might get run over. If there is a better (read: already known) method for isolating the node ID and the payload, I would really appreciate it if you could point me in th right direction. If you know where such an example may be found, I would love to see it. I said, when I hit node 11, I am going to experience this problem at th beginning, as well as the end of the string of data.

    Thanks Again - Baran

    Troubleshooting

  • Close but no cigar . . .
    B Baran

    Greetings,

    I have made a variation of the Serial Gateway and I have inserted the following in the void serial.Event Loop:

    void serialEvent() {
    while (Serial.available()) {

     //  look for the next valid integer in the incoming serial stream - this is  the node:
    int node = Serial.parseInt(); 
    // do it again, but throw it away:
    int w = Serial.parseInt(); 
    // do it again, but throw it away:
    int x = Serial.parseInt(); 
    // do it again, but throw it away:    
    int y = Serial.parseInt(); 
    // do it again, this is the Payload:
    int z = Serial.parseInt(); 
    // do it again, this is the current reading:
    int current = Serial.parseInt();
    
      // print the node and payload
      Serial.print("    The Node is :");
      Serial.print(node);
      Serial.print("    The Command is :");
      Serial.print(z);
      Serial.print("    The Payload is :");
      Serial.println(current);
    }   
    

    }

    I am certain that someone with programming knowledge will immediately see my problem. My payload can be up to four digits long, yet the above process seems to only grab the last byte of the 1 to 4-digit (depending on the analog value) number that is the payload. Can someone show me how to tweak the last Serial.parseInt() statement into something that captures the entire payload? I also see how the same thing will occur when I have more than 10 nodes (0-9).

    Appreciatively - Baran

    Troubleshooting

  • Controller Code that Demonstrates Integer Parsing
    B Baran

    Greetings,

    Way too cool! I appreciate the illustration. I need to get to sleep but I will play with it tomorrow evening after work. I just wanted to say thank you for giving me a guide.

    Respectfully - Baran

    Controllers

  • Controller Code that Demonstrates Integer Parsing
    B Baran

    Hi Bulldog,

    I am trying to parse typical node output data. When queried, my nodes send the analog data from each of the eight analog inputs. A typical output might look like:

    1;0;1;0;17;354
    1;0;1;0;17;422
    1;0;1;0;17;423
    1;0;1;0;17;519
    1;0;1;0;17;527
    1;0;1;0;17;439
    1;0;1;0;17;484
    1;0;1;0;17;406

    The first byte is the node ID, and I do not care about the second, third, fourth, or fifth bytes. The sixth byte is the payload or data from an analog input. I would like to, ideally, parse the 1st and 6th bytes from each line and store the data in an array, possibly in flash memory on a Mega board. The problem is, I am so new to this, I am not sure how to begin to even present something to work on. My hope is that someone who recognizes this as being similar to a question from an earlier time can direct me to a sample that might serve to illustrate how this process can be made to happen. In the best of all possible worlds, someone may say "oh yeah, here's how you do it". Hey . . . a newbie can dream.

    Controllers

  • Controller Code that Demonstrates Integer Parsing
    B Baran

    I appreciate your suggestion but I know litte to nothing about coding. I was hoping to view a working example of some sort of parsing that might serve as a template for this module.

    Controllers

  • Controller Code that Demonstrates Integer Parsing
    B Baran

    Hi Everyone,

    I know I was looking at some C++ code on this site awhile back that parsed out the node and payload information from a serial data string. Would someone be so kind as to direct me to a similar example - code that grabs incoming serial data using the semicolon as a parsing guide?

    Thanks for any and all suggestions - Baran

    Controllers

  • Restricting Node Output Data to the Gateway
    B Baran

    Hi Again,

    Thanks;)-.

    Troubleshooting

  • Restricting Node Output Data to the Gateway
    B Baran

    Hi Everyone,

    I have a gateway that requests data from one node at a time. Each node streams data readings from analog inputs 1 through 8. Including my request, the code looks like this:

    1;0;2;1;17;
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:418
    1;0;1;0;17;418
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:406
    1;0;1;0;17;406
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:476
    1;0;1;0;17;476
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:520
    1;0;1;0;17;520
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:526
    1;0;1;0;17;526
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:350
    1;0;1;0;17;350
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:487
    1;0;1;0;17;487
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:343
    1;0;1;0;17;343

    My question is, can I "mute" the node from sending lines that look like:
    "0;0;3;0;9;read: 1-1-0 s=0,c=1,t=17,pt=2,l=2:343" while sending lines that look like:
    "1;0;1;0;17;343"? The information that I need is redundant and eliminating a line would result in less information to have to decode on my gateway side and would increase speed, as well. Another way of saying it is that I am only interested in the node ID and the payload, as I know the sensor ID base upon the data stream (0 - 7).

    Thank you for any suggestions - Baran

    Troubleshooting

  • Do I have an error or am I mistaken?
    B Baran

    Greetings Hek,

    I am never sending messages to my nodes, only requests for data from the analog sensors. As I am already receiving analog inputs 0 through 7, I have no need to present eight different sensors. What I am unable to get right is the message that I would send to a node (like the script above) that would cause it to unleash one round of sensor data. I know the first number is the node, itself. The second number is the sensor but that is weird here because all sensors are read in one shot. Should I simply call it sensor 0 to match the CHILD_ID_POWER? I know the third number is a request if it is a "2" and the fourth can be a "0" for no ack. As I call MyMessage msg with V_WATT, the fifth number is "17" so, in my mind (and nowhere else because it does not work;), the code my gateway should send to node 1 to request data is 1,0,2,0,17/n. I am wrong, of course, because it doesn't work. If anyone could set me straight, I would deeply appreciate it. Also, thanks to Chester for the IF statement advice.. As a PS, my nodes communicate well and my gateway notices when my node is activated.

    Troubleshooting

  • Do I have an error or am I mistaken?
    B Baran

    Greetings,

    A simple variation of the following code (with the for statement in the void loop and no incomingMessage statements) transmits the analog output of A0 through A7 to my gateway - repeatedly! I am trying to make this happen only when the gateway requests data. I am not presenting sensors, as I am only interested in the payload and the node ID (1, in this example).

    My question is . . . do I have this right (below)? If I do, would someone be so kind as to suggest the gateway code that will request that this node "dump" its message data to the Gateway? I have tried 1;255;2;0;17/n, and similar variations, to no avail If I have this wrong, what might I be missing to respond to a message from the gateway. As a side note, since this routine sends A0 - A7 in succession, I don't have a specific sensor ID to respond. Should the second number in my gateway code be 255 for non-descript sensor requests, and finally, do I need a subtype if I am not filtering for one?

    Many thanks for any constructive input (remembering I am in C++ kindergarten) - Baran

    #include <SPI.h>
    #include <MySensor.h>
    int AnalogSensorPin=0;
    int AnalogLevel;
    #define CHILD_ID_POWER 0

    MySensor gw;
    MyMessage msg(CHILD_ID_POWER, V_WATT);

    void setup()
    {
    gw.begin(incomingMessage, AUTO, true);
    // Register all sensors to gateway (they will be created as child devices)
    gw.present(CHILD_ID_POWER, S_POWER);
    }

    void loop()
    {
    // Alway process incoming messages whenever possible
    gw.process();
    }

    void incomingMessage(const MyMessage &message) {
    for (AnalogSensorPin = 0; AnalogSensorPin < 8; AnalogSensorPin ++){
    AnalogLevel = (analogRead(AnalogSensorPin));
    Serial.print(" DC Current from String Number");
    Serial.print (AnalogSensorPin+1); // This prints on the sensor side, not the gateway side!
    Serial.print (" ");
    Serial.println(AnalogLevel);
    gw.send(msg.set(AnalogLevel));
    }
    }

    Troubleshooting

  • Responding to a Gateway Query
    B Baran

    Greetings All,

    Hek was kind enough to suggest the ways and means of querying a node for data. I have my nodes set up to send data automatically. I would like to test for the incoming query with an "IF" statement but, once again, I need a push. I cannot seem to incorporate my incomingMessage () without compiling errors, probably because I do not know what I am doing.

    If I may be so bold as to request a bit of code, what might I place into an "IF" statement or my void loop to test for when the gateway has sent a request for information?

    Right now, I have my gateway sending the following code: 1;3;2;0;39\n which translates into a no-ack (0) request for data (2) from node 1, child sensor 3, in the form of a current level reading (39). I just don't know how to respond to this request. All advice is greatly appreciated! Directions to an example would be great, as well, because I do not know what to search for.

    Troubleshooting

  • Serial Gateway Code to Query Node's Payload?
    B Baran

    Hek said "You can send just send a value (SET) or use use the special request command (REQ) from your controller."

    Sounds good, but my ignorance is deeper than you imagined. I do not have a controller, as I wish to send a suitable "request node data" through my serial gateway. Would someone please show me an example of serial code that would make such a request?

    Respectfully - Baran

    Troubleshooting

  • Serial Gateway Code to Query Node's Payload?
    B Baran

    Greetings All,

    Would someone please give me an example of a line of serial gateway code that would query node x for its payload data? I have around 100 nodes so I do not want them randomly broadcasting data . . . that would lead to much cross-talk and lost data. Rather, I would like my serial gateway to ask, for example, "node 1, give me your data" and node 1 will present its sensor data. I tried to search the database but I could not filter properly to find an example. I feel stupid and lost and a little help here would really lift my spirits and get me moving on this. With great appreciation to all who respond - Baran

    Troubleshooting

  • Changing Node IDs on the fly?!?
    B Baran

    Good Point;)-

    Troubleshooting

  • Changing Node IDs on the fly?!?
    B Baran

    Greetings,

    Would someone be so kind as to print the line of code that my serial interface should send to a previously identified node to change its node ID? I saw a line of code in a recent post that was supposed to do this but I could not make it work. For arguments sake, let's say I have a node that was previously assigned an ID of 100 and now I want the serial interface to tell it to be 125 instead.

    With Appreciation - Baran

    Troubleshooting
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular