Rak 5010 Getting Sensor Data

Issue: Software

Setup:

Details: Hey guys I am actually trying to write a function in my main in user_app.c file to read the sensor data however everytime I read the data, the data values for all the sensor datas is being shown as 0 like for temp its showing 0, for humidity 0, for battery 0V and so on. So I am not sure as to was it going on?

Hi,

You can refer to this part of code in line 498:

Actually @nero I am doing this only but its still showing 0 for all sensor values in user_app.c file however if I try to do the same thing in at.c file using an at command it works. So I am not too sure. Could you maybe help me further?

Maybe you can download our last 5010 firmware:

And send at+get_config=device:status to check the hardware normal or not.
If it is ok, can you post your code? We can check in details.

Hi @nero, it still hasn’t worked. Here is the link to the zip file of my code. APN is defined as a macro to enter the AP, IP as a macro for the IP address and the PORT as a macro for the Port number.

https://drive.google.com/file/d/13ABqvCEraC2BeKQsqssz1XxicZQ6c-UW/view?usp=sharing

Hi,
Is our firmware ok? I want to exclude the problem of hardware.

Yes @nero, the firmware is ok and the hardware is also ok because when I do the at command for device status the sensor data information is correct

OK, it must be the code problem. Can you send your code to [email protected]. Because the net problem ,I can’t download it. Besides, please concentrate your issues in one topic. It is really difficult to follow. As for rui_device_sleep(1), it will power off bg96 and sensors. rui_device_sleep(0) will wake them.

Hey @nero I will try to post all the questions in a single topic next time. Sorry about that and I have emailed you the code.

OK, have got your code. I will test later.

Regards,
Nero

Hi, you can do as follow with a timer. But you should notice:

  1. rui_device_sleep(1) will power off bg96 and make all sensors sleep for save power maximized. It should cooperate with rui_device_sleep(0). And it costs times at least 1min or more. In IOT situation, node will not wake up often and sleep most of time. So delay several seconds has no practical significance. It won’t save power better than keep work if sleep a little time.
  2. You’d better run your task by the timer. There is no OS now. So timer is the best way.
  3. I got the sensors data and all ok.

#include “rui.h”
#include “lis3dh.h”
#include “opt3001.h”
#include “shtc3.h”
#include “lps22hb.h”

#define APN “pwg”
#define PORT
#define IP

RUI_I2C_ST st = {0};

uint8_t send_data[256]={0};

uint8_t at_rsp[1536] = {0};

void sendOk();

void sensor_on(void)
{

st.PIN_SDA = 14;
st.PIN_SCL = 13;
st.FREQUENCY = RUI_I2C_FREQ_400K;
rui_i2c_init(&st);

//lis3dh init
lis3dh_init();
//opt3001 init
opt3001_init();
//shtc3 init
SHTC3_Wakeup();
//lps22hb init 1 wake up
lps22hb_mode(1);

}

void sensor_off(void)
{
lis3dh_sleep_init();
sensorOpt3001Enable(0);
SHTC3_Sleep();
lps22hb_mode(0);
}

RUI_TIMER_ST rui_timer;
uint8_t timer_flag=0;
void timer_callback(void)
{
timer_flag = 1;
}

void timer_init()
{
rui_timer.timer_mode = RUI_TIMER_MODE_REPEATED;
rui_timer_init(&rui_timer, timer_callback);
rui_timer_setvalue(&rui_timer, 120000);
rui_timer_start(&rui_timer);
}

void main(void)
{
//system init
rui_sensor_register_callback(sensor_on,sensor_off);
rui_init();
timer_init();

while(1)
{
    if (timer_flag == 1)
    {

        sendOk();
        timer_flag = 0;
    }
    rui_running();
}

}

void sendOk()
{

uint8_t gsm_cmd[100] = {0};
uint8_t gsm_rsp[256] = {0};
float temp = 0;                     //Variables which will store sensor data
float humidity = 0;
float pressure = 0;                                 
int x = 0;
int y = 0;
int z = 0;
float magnetic_x = 0;
float magnetic_y = 0;
float magnetic_z = 0;
float light = 0;
float voltage = 0;
RUI_GPS_DATA g_gps_data = {0};
uint8_t lat_data[20] = {0}; 
uint8_t lon_data[20] = {0}; 
uint8_t lora_config_data[10] = {0};



 float _x = 0;
float _y = 0;
float _z = 0;
get_lps22hb_data(&pressure);
get_lis3dh_data(&x,&y,&z);
_x =x * 4000/65536;
_y =y * 4000/65536;
_z =z * 4000/65536;   
get_opt3001_data(&light);
SHTC3_GetTempAndHumi(&temp,&humidity);

memset(lat_data,0,20);        
rui_gps_get(&g_gps_data);
sprintf(lat_data,"%lf",g_gps_data.Latitude);
memset(lon_data,0,20);
sprintf(lon_data,"%lf",g_gps_data.Longitude);
rui_device_get_battery_level(&voltage);
memset(gsm_cmd,0,100);
memset(gsm_rsp,0,256);
memset(send_data,0,256); 


//sprintf(send_data,"Acc:%.2f,%.2f,%.2f; ",_x,_y,_z); //Not Adding acceleration to reduce the size of send_data variable as it is to be stored in flash because of which it has to be of size less than 128 bytes

sprintf(send_data+strlen(send_data),"Tem:%.2f;Hum:%.2f; ",temp,humidity);

sprintf(send_data+strlen(send_data),"Pre:%.2f; ",pressure);

sprintf(send_data+strlen(send_data),"Lig:%.2f; ",light);

sprintf(send_data+strlen(send_data),"Lat(0-N,1-S):%d,%s,Lon(0-E,1-W):%d,%s; ",g_gps_data.LatitudeNS,lat_data,g_gps_data.LongitudaEW,lon_data); 

if(voltage>0)
{   
   sprintf(send_data+strlen(send_data),"Battery:%.2f; ",voltage);
}


//MAKE SURE THE FIRST PARAMETER IS ALWAYS RUI_FLASH_USER and MAKE SURE THE SIZE OF VARIABLE WHOSE VALUE NEEDS TO BE PRESERVED SHOULD BE LESS THAN 128 BYTES
 //rui_flash_write(RUI_FLASH_USER, send_data, strlen(send_data)); //Writing the value of send_data in the flash memory

/*
if(power_flag == 0)
{
rui_device_sleep(1); //Sleep
power_flag =1;
}
*/
//rui_delay_ms(10); //Delay between sleep and wakeup

//memcpy(at_rsp+strlen(at_rsp),"WAKING UP AFTER DELAY",strlen("WAKING UP AFTER DELAY"));
//rui_at_response(true, at_rsp, RAK_OK);

/*
rui_device_sleep(0); //WakeUp
power_flag = 0;
*/

//rui_flash_read(RUI_FLASH_USER,send_data, strlen(send_data)); //Reading value of send_data from the flash

rui_cellular_send("AT+CSQ");        //Checking signal strength
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

memset(gsm_cmd,0,100);
sprintf(gsm_cmd, "AT+QICSGP=1,1,\"%s\"", APN);

rui_cellular_send(gsm_cmd);    //Connecting to a cellular network
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

rui_cellular_send("AT+QIACT=1");        //Activating the cellular connection
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

rui_cellular_send("AT+QIACT?");         //Checking activation status
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

memset(gsm_cmd,0,100);
sprintf(gsm_cmd, "AT+QIOPEN=1,0,\"UDP\",\"%s\",%s,1,1", IP, PORT);


rui_cellular_send(gsm_cmd);   //Opening UDP socket with apporpriate port and ip address
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

rui_cellular_send("AT+QISTATE=0,1");    //Checking state of connection established
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

memset(gsm_cmd,0,100);
sprintf(gsm_cmd, "AT+QISEND=0,%d", strlen(send_data));      //Sending data
rui_cellular_send(gsm_cmd);
rui_delay_ms(2000);

rui_cellular_send(send_data);
memset(gsm_rsp,0,256);
rui_cellular_response(gsm_rsp, 256, 500 * 20);

rui_cellular_send("AT+CLOSE=0");        //Closing Socket
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

rui_cellular_send("AT+QIDEACT=0");      //Deactivating cellular connection
rui_cellular_response(gsm_rsp, 256, 500 * 60);
memset(gsm_rsp,0,256);

return;

}

Hey @nero for some reason I cant see the full code could you email me all the set of files for the code at [email protected]?

Hey @nero I have received your code and I ran it but I am sorry to bother you again but I am still getting 0 values for the sensor data being send via UDP. So I am once again not sure as to what is happening, I have even tried it on two of my rak5010 boards so I am confused as to what is happening

Can you post your data shown on your sever?

This is what it showed me @nero, I have cut off the IP and PORT part but this is the log of the data send to me and received by my packet sender and the data is Tem:-0.00;Hum:0.00; Pre:-0.00; Lat(0-N,1-S):0,0.000000,Lon(0-E,1-W):1,0.000000; Battery:-0.00;

LOG of Packet Sender
TIME From IP From Port To IP To Port Method Error ASCII Hex

02:31:58 20240 You UDP \nTem:-0.00;Hum:0.00; Pre:-0.00; Lat(0-N,1-S):0,0.000000,Lon(0-E,1-W):1,0.000000; Battery:-0.00; 0A 54 65 6D 3A 2D 30 2E 30 30 3B 48 75 6D 3A 30 2E 30 30 3B 20 50 72 65 3A 2D 30 2E 30 30 3B 20 4C 61 74 28 30 2D 4E 2C 31 2D 53 29 3A 30 2C 30 2E 30 30 30 30 30 30 2C 4C 6F 6E 28 30 2D 45 2C 31 2D 57 29 3A 31 2C 30 2E 30 30 30 30 30 30 3B 20 42 61 74 74 65 72 79 3A 2D 30 2E 30 30 3B

It looks no problem on code… Can you add log print. Check the where the data missing.

sprintf(send_data+strlen(send_data),"Tem:%.2f;Hum:%.2f; ",temp,humidity);
RUI_LOG_PRINTF(send_data);
sprintf(send_data+strlen(send_data),"Pre:%.2f; ",pressure);
RUI_LOG_PRINTF(send_data);
sprintf(send_data+strlen(send_data),"Lig:%.2f; ",light);
RUI_LOG_PRINTF(send_data);
sprintf(send_data+strlen(send_data),"Lat(0-N,1-S):%d,%s,Lon(0-E,1-W):%d,%s; ",g_gps_data.LatitudeNS,lat_data,g_gps_data.LongitudaEW,lon_data);
RUI_LOG_PRINTF(send_data);
if(voltage>0)
{
sprintf(send_data+strlen(send_data),"Battery:%.2f; ",voltage);
}
RUI_LOG_PRINTF(send_data);

Check with Jlink RTT viewer

Hey @nero would I be required to have a jlink base to get the RTT data via Jlink RTT viewer?

You do not have Jlink? What do you use to burn? If no Jlink, can you fill any other data to the send_data buffer. To check which part is not correct.

Or try fill like :

sprintf(send_data,"Tem:%.2f;Hum:%.2f; ",temp,humidity);

sprintf(send_data+strlen(send_data),"Pre:%.2f; ",pressure);

sprintf(send_data+strlen(send_data),"Lig:%.2f; ",light);

sprintf(send_data+strlen(send_data),"Lat(0-N,1-S):%d,%s,Lon(0-E,1-W):%d,%s; ",g_gps_data.LatitudeNS,lat_data,g_gps_data.LongitudaEW,lon_data);

if(voltage>0)
{
sprintf(send_data+strlen(send_data),"Battery:%.2f; ",voltage);
}