Invalid conversion from 'int' to 'xref2u1_t {aka unsigned char*}'

Hi,

Handling various data types is a common question, but I have spent a couple of hours trying to find a solution to my specific problem, without success. So I apologise that I am going to be covering ground that has no doubt been asked before.

I'm currently merging a few sketches I've previously made to create a LORAWAN soil moisture sensor. It's mid-way through development, however I've hit a hurdle in parsing the sensor data so that it can be sent over the LORA connection.

The error message is "invalid conversion from 'int' to 'xref2u1_t {aka unsigned char*}' [-fpermissive]" and is directly related to my change from the original payload variable to the sensor one. I believe the problem is created here:

static uint8_t mydata[] = "Hello, world!";
int soilMoistureValue1 = 0;
....
LMIC_setTxData2(1, soilMoistureValue1, sizeof(soilMoistureValue1)-1, 0);

Using the 'mydata' variable in the above example works, the moisture one errors as described above. soilMoistureValue1 is a number between 0 and 4095.

I therefore need to convert the soilMostureValue1 into the uint8_t format, but can't figure out how to do it. Happy to change the range of soilMoistureValue1 to be 0-255 or even 0-100. I'm simply trying to share a percentage with an automation setup, so the granularity is not that important.

Full code can be found here: #include <lmic.h>#include <hal/hal.h>#include <SPI.h>// LoRaWAN vari - Pastebin.com

TIA.

Try this cast:

LMIC_setTxData2(1, (xref2u1_t)&soilMoistureValue1, sizeof(soilMoistureValue1), 0);
1 Like

Eureka! That works.

Thank you so much for your help.