My Loops are out of sync.
-
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; } } }
-
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...
1 out of 2
Suggested Topics
-
Day 1 - Status report
Announcements ⢠23 Mar 2014, 22:45 ⢠hek 24 Mar 2014, 20:12 -
Can not compile MySensors on esp8266
Troubleshooting ⢠24 Aug 2024, 15:35 ⢠TheoL 29 Aug 2024, 20:47 -
JSN SR04T - Temperature Influencing Readings
Troubleshooting ⢠6 Sept 2019, 07:51 ⢠Timbergetter 18 days ago -
Getting system time from the controller
Troubleshooting ⢠27 Feb 2025, 01:39 ⢠dpcons 3 Mar 2025, 01:00 -
Forum Search not working?
Troubleshooting ⢠4 Oct 2023, 23:33 ⢠Gibber 2 Sept 2024, 20:28 -
Ghost Child
Troubleshooting ⢠15 Mar 2025, 07:44 ⢠FcNanoLed 28 days ago