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
  1. Home
  2. Troubleshooting
  3. My Loops are out of sync.

My Loops are out of sync.

Scheduled Pinned Locked Moved Troubleshooting
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Baran
    wrote on last edited by marceltrapman
    #1

    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;
        }
        }   
      }
    
    1 Reply Last reply
    0
    • marceltrapmanM Offline
      marceltrapmanM Offline
      marceltrapman
      Mod
      wrote on last edited by marceltrapman
      #2

      Hi,

      I edited your post to show the code as it should :)

      Remove ' i = i+1;'.

      It is obsolete. You already do this with 'i++' where you define your loop...

      Fulltime Servoy Developer
      Parttime Moderator MySensors board

      I use Domoticz as controller for Z-Wave and MySensors (previously Indigo and OpenHAB).
      I have a FABtotum to print cases.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      14

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

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