Hi
I have a project where I want to send sensor-data from my arduino via my HM-10 bluetooth module to an android app for visualisation. So I am testing transmission with a toy project.
I am sending raw bytes (from a struct) over a softwareSerial connection.
#include <SoftwareSerial.h>
#include "typedefs.h"
SoftwareSerial mySerial(2, 3);
sensorPack constructPack(unsigned long t,int v){
sensorPack result;
result.data.pre=0xFF;
result.data.post=0xFF;
result.data.time=t;
result.data.value=v;
return result;
}
void setup()
{
Serial.begin(9600);
while (!Serial) {}
mySerial.begin(9600);
}
void loop()
{
sensorPack cur = constructPack((unsigned long)1,(float)1.0);
mySerial.write(cur.raw,10);
//Code to print bytes to string
int size = 10;
int i;
char* buf_str = (char*) malloc (2*size + 1);
char* buf_ptr = buf_str;
for (i = 0; i < size; i++){
buf_ptr += sprintf(buf_ptr, "%02X", cur.raw[i]);
}
sprintf(buf_ptr,"\n");
*(buf_ptr + 1) = '\0';
Serial.println(buf_str);
delay(5000);
}
typedefs.h
#ifndef _LOADED_H
#define _LOADED_H
typedef struct sensorData{
unsigned char pre;
unsigned long time;
float value;
unsigned char post;
};
typedef union sensorPack{
sensorData data;
unsigned char raw[10];
};
#endif
Over the regular serial connection I get "FF010000000000803FFF" (FF 0100 0000 0000 803F FF) as expected.
However using the app 'nRF Master Control Panel' on my Android phone I receive all sorts of data packets
V 14:21:03.969 Notifications enabled for 0000ffe1-0000-1000-8000-00805f9b34fb
I 14:21:05.123 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-80-3F-FF-00
A 14:21:05.218 "(0x) FF-01-00-00-00-00-00-80-3F-FF-00" received
I 14:21:10.126 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-FA
A 14:21:10.163 "(0x) FF-01-00-00-00-00-00-FA" received
I 14:21:15.143 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-80-3F-FF-00
A 14:21:15.158 "(0x) FF-01-00-00-00-00-00-80-3F-FF-00" received
I 14:21:20.143 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-00-F8
A 14:21:20.168 "(0x) FF-01-00-00-00-00-00-00-F8" received
I 14:21:25.172 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-80-3F-FF
A 14:21:25.197 "(0x) FF-01-00-00-00-00-80-3F-FF" received
I 14:21:26.572 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-80-3F-FF
A 14:21:26.604 "(0x) FF-01-00-00-00-00-80-3F-FF" received
I 14:21:31.568 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-80-3F-FF
A 14:21:31.600 "(0x) FF-01-00-00-00-00-00-80-3F-FF" received
I 14:21:36.590 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-FA
A 14:21:36.623 "(0x) FF-01-00-00-00-00-00-FA" received
I 14:21:41.592 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-80-3F-FF
A 14:21:41.631 "(0x) FF-01-00-00-00-00-80-3F-FF" received
I 14:21:46.612 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-00-00-00
A 14:21:46.654 "(0x) FF-01-00-00-00-00-00-00-00" received
I 14:21:51.616 Notification received from 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) FF-01-00-00-00-00-80-3F-FF
A 14:21:51.651 "(0x) FF-01-00-00-00-00-80-3F-FF" received
Is this behavior normal? Is extra bookkeeping data sent? Is the data corrupt and should I include error-correction?
Other tips?
Kind regards
Jasper