Best way to send serial data wirelessly???

All,

I have a data logger installed on a small go cart and I've built a wireless transmitter to send data back to the pit using HC-12's. Whats the best way to send data? currently i'm creating a comma delimited string, sending that, then parsing it on the receiving end. Works, but is there a better way? To increase range i'm sending at 1200 baud.

Requirements

  1. send 40-50 bytes every second
  2. distance 1000 meters or so (range may be an issue, but i don't need 100% reliability)
  3. car speed around 25 MPH
  4. security needs, none really. If another team can figure out how to get our data--they can have it :slight_smile:

My stripped down code is attached if you want to have a look.

//////////////////////////
// transmitter code
// uses HC-12

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

unsigned long point, cartime;
double volts, amps, carspeed;
String Parameter[10];
String data;


void setup() {

  Serial.begin(1200);
  mySerial.begin(1200);
  mySerial.setTimeout(50);

}

void loop() {

  ComputeData();
  SendData;
  PrintData();

}

void SendData() {

  // build the string

  data = String(point) + "," +
         String(cartime, 2)  + "," +
         String(volts, 1)     + "," +
         String(amps, 1)      + "," +
         String(carspeed, 1);

  // note string will look something like this
  // "1224,23.32,24.4,15.2,25.2"
  mySerial.print(data);

}

void ComputeData() {

  // i have functions to get this, but hard codeing examples for example
  point++;
  cartime = millis() / 1000.0;
  volts = 24.4;
  amps = 15.2;
  carspeed = 25.2;

}

void PrintData() {
  Serial.println("Data****************************");
  Serial.print("point ");
  Serial.println(point);
  Serial.print("curtime ");
  Serial.println(cartime, 2);
  Serial.print("volts ");
  Serial.println(volts, 1);
  Serial.print("amps ");
  Serial.println(amps, 1);
  Serial.print("carspeed ");
  Serial.println(carspeed, 1);

}

// end transmitter code
//////////////////////////////////////////////////




//////////////////////////////////////////////////
// receiver code
// uses HC-12

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 3);

unsigned long point, cartime;
double volts, amps, carspeed;
String Parameter[10];
String data;

void setup() {

  Serial.begin(1200);

  mySerial.begin(1200);
  mySerial.setTimeout(100);

  pinMode(6, INPUT);
  pinMode(3, OUTPUT);

}

void loop(void) {

  GetData();
  PrintData();

}

void GetData() {

  if (mySerial.available() > 0) {

    data = mySerial.readString();

    // note data will look something like this
    // "1224,23.32,24.4,15.2,25.2"
    
    ParseData(data, ',', Parameter);

    point = Parameter[0].toFloat();
    cartime = Parameter[1].toFloat();
    volts = Parameter[2].toFloat();
    amps = Parameter[3].toFloat();
    carspeed = Parameter[8].toFloat();
  }
}

void ParseData(String sInput, char cDelim, String sParams[]) {

  int iPosDelim, iPosStart = 0;
  int iParamCount = 0;

  while (iPosDelim != sInput.length()) {
    iPosDelim = sInput.indexOf(cDelim, iPosStart);

    if (iPosDelim == -1) {
      iPosDelim = sInput.length();
    }
    sParams[iParamCount] = sInput.substring(iPosStart, iPosDelim );

    iParamCount++;
    iPosStart = iPosDelim + 1;

  }

}

void PrintData() {
  Serial.println("Data****************************");
  Serial.print("point ");
  Serial.println(point);
  Serial.print("curtime ");
  Serial.println(cartime);
  Serial.print("volts ");
  Serial.println(volts);
  Serial.print("amps ");
  Serial.println(amps);
  Serial.print("carspeed ");
  Serial.println(carspeed);
  
}

// end receiver code
//////////////////////////////////////////////////

If its working....

then I dont think HOW you format or parse the data really matters. (its up to you and how you want to send/receive/handle the feedback)

Are there any issues?

drop of data? missing?

reason i was asking is I was sending parsed strings using an nRV24L01, then someone suggested to pass a structure--which was much easier to do.

heck for all i know there's a better way, hence the question here.

You would send fewer bytes per transmission in binary format.

All those String operations are likely to crash the Arduino after a while, due to memory fragmentation.

For a project I am working on I decided to convert numbers to text character by calculating base64 values and adding 48. Two characters can send +/-2048 or 0-4096 and 3 characters can send +/-131072. Converting the values back to numbers takes about 1/10th of the time of the atoi() function and the data stream is human-readable which makes checking easier. And my data stream is a fixed length so I can parse it just by reading the characters at different locations.

...R

For one, if you after a 1000M range at ground level, then you might struggle with the HC12s or nRV24L01, it could work, maybe just.

Use LoRa devices , they will go at least 10 times further for the same power and speed.

My tracker application is very close to what you are trying to do, the Pro Mini based device reads a GPS and sensors and sends a payload of around 64 bytes in CSV which is a mix of floats, ints, bytes and ASCII. A matching receiver translates it all.

I also have very long range binary (x3) payload that sends the position and altitude information as 2 binary floats and an int, thats 10 bytes only.

The whole setup is two way of course, you can from the base station control and change the way the remote tracker operates.

I tend to use a data rate of 1500bps for the tracker, range with good line of sight ground to balloon is circa 250km @ 10mW.

srnet:
Use LoRa devices , they will go at least 10 times further for the same power and speed.

Interesting. Can you post a link to a datasheet or a supplier's web page?

...R

Robin2:
Interesting. Can you post a link to a datasheet or a supplier's web page?
...R

Google 'Semtech SX1278' and you should find it.

Semtech knew the devices were long range, but they did not appreciate just how good they were, until I sent them the report on my various 'experiments'.

That report was one of a series that are on my dropbox, see the links page here;

www.LoRaTracker.uk

The 10 times range comes from an exact duplicate of the 40km hilltop to hilltop test I had carried out with the Si4432 FSK device as part of the $50SAT project.

Thanks. I have bookmarked that.

Do those frequencies require a licence in the UK?

...R

Robin2:
Thanks. I have bookmarked that.

Do those frequencies require a licence in the UK?

...R

Not if they are used as license exempt ISM devices @ 10mW.

If anyone wants a relativly easy read on the capabilities of LoRa, I suggest you look at;

Semtech LoRa Transceivers – a KISS approach to Long Range Data Telemetry - January 2015.pdf