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
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
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;
}
}
}
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
@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
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'
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
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
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
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
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
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.
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.