2

tldr; I am writing a mesh network software using arduinos. I need to wirelessly receive, process, and transmit data, all simultaneously. I am aware of protothreads library, and the other software solutions, such as using interrupts, however, I am using relatively high baud rates. Thus each nanosecond is of the essence. Does anyone have any other ideas for me to achieve this? my initial thought is to have 2 Arduinos functioning as a single node in the mesh. One will receive while the other transmits.

I am currently using these antennas to receive and send messages. I want to create a mesh network of Arduinos using these modules. I found several mesh libraries for Arduino, but none seem to quite do the task I need. So here is my plan which I will work through using an example. (This is a very naive explanation, and has flaws in it's implementation. This is just to give off the general idea).

Each Arduino will be connected to a receiver and a transmitter. Let's say I have just 4 nodes in the mesh.

  1. Node #1 -> Address = 0xA031
  2. Node #2 -> Address = 0xB042
  3. Node #3 -> Address = 0xC053
  4. Node #4 -> Address = 0xD064

I send a message to node A through USB. Let's say the message is "SOS!" Node A will reconstruct the message in the following way so that the new message is "0xA031_SOS!"

Now, Node A will begin transmitting this message continually. Let's say only Node C picks up the message. Node C will pick up the message and perform the following checks. (I will have 2 queues. A receiving queue and a transmitting queue. So as soon as a node receives a message, it will be placed in the receiving queue. And then it will run the following checks before sending it to the transmitting queue.)

  1. Is the address a recognized/valid address? Handle appropriately
  2. Is the address of the received message the same as the node's own address?

    If address is same, check if the message received is the same message being transmitted currently by itself. If so, discard the message and tell transmitter to stop transmitting that message(This means that the message was originally transmitted to another node and came back, which means, it doesn't need to be re-transmitted any more). If the address is not the same, then send the message to the transmission queue.

Now the transmission will be handled the following way.

  1. Check if there is anything in the transmission queue. If there is, transmit this message continually until told not to.
  2. If the transmitter is told to not transmit that message any longer, that message will be popped of the queue.

So what happens? Node A continually sends a message. Node C receives the message and re-transmits. Because Node C was able to pick up Node A's message, it is in range and Node A will pick up Node C's message. Now, Node A will check the address, and say "oh, this is the same address as me." Then it will check if the message being transmitted is the same as what was received. If so, then it will tell the transmission queue to no longer transmit that message. (This almost like a form of back propagation).

Now I realize there are a million ways to have collisions and infinite loops. I will be eventually writing a software to resolve these things. But I hope I am giving off the general idea of how the network will work.

My questions:

  1. As is clear from my explanation, because I am receiving and transmitting simultaneously, is there a way for me to do multi-threading? I am aware of protothreads and the other things mentioned in this post. However, all of them only offer a software solution, and not a hardware solution. So does anyone have any ideas of how I'd work around this? My initial thought is to have each node be composed of 2 Arduinos. Any one have any other ideas?
  2. Also, does anyone have a better idea of implementing the mesh to do what I want it to?

I know this is a very convoluted, hefty post. Please let me know what I should clarify. Thank you.

10
  • 1
    It is not clear from your explanation why you would want threads at all. void loop() { process_snd_queue(); process_rcv_queue(); }. As long as you do not use blocking calls (see Blink without delay), that should work just fine. Feb 29, 2016 at 8:45
  • Well, I am constantly receiving, and at the same time, I am processing the received data and transmitting data. The arduino either receives or processes or transmits the data. But it's not able to do this simultaneously. This wouldn't be too much of a problem, but timing must be maintained given the high baud rate I am using.
    – Jonathan
    Feb 29, 2016 at 8:48
  • I hope I'm not completely missing what you're suggesting.
    – Jonathan
    Feb 29, 2016 at 8:48
  • The Arduino has a hardware UART which enables it to send, process and receive, all at the same time. If you take care not to fill the send buffer, then Serial.print() returns immediately, and you can do other stuff while the data is sent in the background. Receiving is also done on the background: just call Serial.available() from time to time to see if you have received something. Feb 29, 2016 at 9:25
  • Here is my "receive" code: arduino.stackexchange.com/questions/17021/… Given this, and my above explanation, when I receive a message with a certain key, I want to send it to another queue that will transmit that data. Now, won't my buffer lose information by the time the information is processed, sent from one queue to another, then transmitted? Especially since the transmission happens continually until the receiver receives a certain key.
    – Jonathan
    Feb 29, 2016 at 9:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy