OK, so it’s not a problem before it even leaves the device.
Your topic title mentions the RAK1904 but there’s no include for the LIS3DH and I can see you’ve hard coded the values. So it must be something else causing the crash.
That said, accelerometer values are floats, so you will at some point either convert them in to something easier to put in to a payload.
But in the meanwhile, you may want to look at the Working with Bytes link as this:
excuse me for my english . The condition when the board is connected on serial port and of course Speaking about accelerometer value output , it’s can be positive or negative, on my device , if one of the three values go negative, the software crash. I’ve see this observing the serial monitor . Is possible see this effects hardcoding the values of accelerometer .
Not a problem, doesn’t matter which language, I still couldn’t figure out which value you were referring to.
You really really need to read the Working with Bytes link - it’s not possible to push floats in to integers and then send them as unsigned bytes.
At present you’ve got your x_axis defined as an uint16 when the LIS3DH library will return a float.
If you change your hard coded value of 13 * 100 to -13 * 100, bad things will happen to the data as the variable is unsigned.
There is some learning to do as much as bug fixing your code.
Here is some code to review:
byte payload[10];
float Temperature = -12.45;
unsigned int TemperatureToSend = (Temperature + 50) * 100;
// This will give a result of (-12.45 + 50) * 100 = 3755
// By using an offset to 50, we can transmit readings as low as -50, you can adjust this value to suit your environment.
// This can then go in to two bytes of a payload:
payload[0] = highByte(TemperatureToSend); // this is an Arduino helper function for ((TemperatureToSend & 0xFF00) >> 8)
payload[1] = lowByte(TemperatureToSend); // this is an Arduino helper function for (TemperatureToSend & 0xFF)
/*
At the decoder end you'd convert this back with ...
Javascript:
var asInt = (payload[0] << 8) + payload[1];
var Temperature = (asInt - 50) / 100;
Python:
asInt = (bytes_data[0] << 8) + bytes_data[1]
Temperature = (asInt - 50) / 100
*/
we ( we are programming in 2 person ) arrived to the code that i had post starting from examples code … but payload we found some trouble on the way … as this one of the accelerometer
@projectsbminfo
I run your code on my WisBlock with the following small change by (trying to make) X negative and then print out the values before adding them to the payload:
And it runs just fine, it does not crash. But of course the X value is very high, because x_axis is an unsigned int, so it converts the negative number to a very high value.
Chip ID=0xFF
BME680 initialized!
Setting DevEUI, etc...
lmh_init response code: 0
GPS uart init ok!
CHARS=0 SENTENCES=0 CSUM ERR=0
** No characters received from GPS: check wiring **
Battery Voltages are: 4206.74mV
Battery Percentage is: 101%%
Battery Percentage_unit8 is: 101%%
result: Tem:295.48C Hum:0.00% Pres:5.12KPa Gas:20177OhmsDevice_Latitude: 0Devic_Longitude: 0Battery=101
X 64236 Y 1400 Z 1500
CHARS=0 SENTENCES=0 CSUM ERR=0
** No characters received from GPS: check wiring **
Battery Voltages are: 4276.43mV
Battery Percentage is: 111%%
Battery Percentage_unit8 is: 111%%
result: Tem:295.48C Hum:0.00% Pres:5.12KPa Gas:20177OhmsDevice_Latitude: 0Devic_Longitude: 0Battery=111
X 64236 Y 1400 Z 1500