Please post with explaination sample node to gateway & back payload

Started by djash40, April 21, 2015, 05:35:02 PM

djash40

String myname="Dave Ashmore"; // as a payload?
How can I send this first from the node to the gateway and then from the gateway back to the node?
I'm new so I was hoping for a detailed line by line example. I saw some stuff on here but it seemed broken up by other questions. Please explain the buffer part too.
Thanks much in advance. Regards Dave.

djash40

I know someone will be tempted to say look at post here or there, but when you are a beginner such as I it is hard to extract out the exact pertinent parts. This could be used as a great sticky post for us beginners.

TomWS

Welcome to the forum, Dave.  The question is how much of a 'beginner' are you?  By this I mean, are you a beginner to Moteino, but you understand C code and how to use Arduino IDE, or are you new to both of these as well?

I'd be happy to provide an annotated Node code which is stripped down to the essential parts needed to
Quote
String myname="Dave Ashmore"; // as a payload?
How can I send this first from the node to the gateway...
but if you need more than this then I think you need to start with one of the many online tutorials on Arduino first.  Let me know...

Tom

djash40

I'm a beginner at both. Able to do some basic stuff . I am however able to use the IDE. I'm a linux user.

djash40

Quote from: TomWS on April 21, 2015, 07:02:57 PM
Welcome to the forum, Dave.  The question is how much of a 'beginner' are you?  By this I mean, are you a beginner to Moteino, but you understand C code and how to use Arduino IDE, or are you new to both of these as well?

I'd be happy to provide an annotated Node code which is stripped down to the essential parts needed to
Quote
String myname="Dave Ashmore"; // as a payload?
How can I send this first from the node to the gateway...
but if you need more than this then I think you need to start with one of the many online tutorials on Arduino first.  Let me know...

Tom

I would love to see this ....:) Thank you.

Felix

David, let me just try to answer your original question. If you have a fixed length string of known length you can just pass it to the send or sendWithRetry function:

send(toNodeID, "message", 7)


Otherwise you can use char arrays to make custom strings, calculate their length and then pass them to the send functions. This is very nicely illustrated in the Gateway and Node examples. Here's an example of reading the FLASH-MEM device ID, compiling it into a string, getting the string length, then passing everything to the send and expecting an ACK back from the destination:

      sprintf(buff, "FLASH_MEM_ID:0x%X", flash.readDeviceId());
      byte buffLen=strlen(buff);
      if (radio.sendWithRetry(GATEWAYID, buff, buffLen))
        Serial.print(" ok!");
      else Serial.print(" nothing...");


This forum is not expressly intended to teach C++ and there are many many other much better places dedicated to that. We try to answer everyone's questions but also we try to stay focused around the released code/examples which are the primary teaching tool for the Arduino/Moteino boards supported here. Some programming/C++ experience is always good to have and expected in order to understand the examples. I try to document the code so that it's easy to understand but I am aware I can't cover all the needs, hence this forum is here for additional coverage.

TomWS

Felix to the rescue!

David, I've been working on a 'simplified' Node example and, after Felix's wake up call, I looked at the code and found I was 277 lines deep (mostly comments, but still) with no immediate end in sight.  Net: is that I'm too torn between simplifying and explaining and find that these tend to be mutually exclusive.  Hence I'm going to abandon this effort for the time being...

Sorry for getting your hopes up.  I hope Felix helped you out.

Tom

djash40

okay so:      String myname="Dave Ashmore"; // as a payload? is 12 char long.
So this:        send(toNodeID, "message", 7)
Can become: send(toNodeID, (myname), 12)
or:   sendWithRetry(toNodeID, (myname), 12)
or
Can become: send(toNodeID, "Dave Ashmore", 12)
or:   sendWithRetry(toNodeID, "Dave Ashmore", 12)

Is that right?
I'll try to break down the other example next.
Bicycle ride first... be back later.

Felix

Don't use Strings in C++, they are dangerous. Use char or byte arrays. You might need to cast them from a type to (const void *) when you pass them to send().
You have to understand pointers and how arrays work in C++. A great place to start on that is here: http://www.cplusplus.com/doc/tutorial/arrays/

djash40

So basically this is not for a hobbyist beginner. I'll either have to learn and entire programming language, abandon my little project or pay someone to make it work.  :(

Felix

The arduino world is the beginner threshold of electronics. Beyond that point is assembly language and beyond than nothing else, maybe whispering to the atmega chip :P but I doubt that works.

Arduinos and Moteinos involve C++ and it's still the best programming language around, so a valuable skill to have. You won't have to learn the "entire" C++ but some basic understanding of C++ should suffice.
The examples I published and many other examples posted in the forums and around lowpowerlab.com give you a head start but you have to try.
Copy pasting won't work, a little reading will get you far far away with hobby electronics.
Paying someone will get the job done once, any changes will cost you again and again. C++ is really not that bad, but again .. you have to try.

djash40

Couldn't someone write a function simular to serial.print whereas a non programmer like myself could pass a string or variable to it and have it pass it on to the radio? Making it easier for a novice like me to do some basic arduino programming.

radio.print(myvariable, "My String");
radio.printwithretry(myvariable, "My String");

That would be so cool.
I've studied some of the code but it's just too greek for me to figure out . Frustrated.
I'd like to know it but it's way too much for me to learn.



Felix

Quote from: djash40 on April 26, 2015, 02:09:09 PM
Couldn't someone write a function simular to serial.print whereas a non programmer like myself could pass a string or variable to it and have it pass it on to the radio? Making it easier for a novice like me to do some basic arduino programming.
Possible, but someone else would want to pass something else, a number, a struct, an array etc etc. So many needs. The given function takes a generic byte array. Just convert your string to that and you're good to go. It's not complicated at all, but that's just my opinion.

djash40

Is there anyone here that I can skype with to teach me how to communicate back and forth with the radios? I've read a bunch of the examples and I'm not quite getting it.

Djash34