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:
- 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.
- You’d better run your task by the timer. There is no OS now. So timer is the best way.
- 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
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);
}
@nero we actually have a script that helps us flash and burn the firmware. Also regarding the code that you sent I have already written that in the user_app.c file. I can probably try to fill some sample temp, humidity values to see if those are being sent or not.
Also I had a question:
This is what I see on tera-term when I flash my code when the code is flashed and ran on the board. So my question is below you can see that the log of sensor data can be observed via uart (I have cut out the IP and Port numbers). And we also see that commands sent to BG96 are echoed to same uart channel. How to use same uart channel to print any debug messages
========================
| ___ / _ \ | | / / | | | () | |
| |/ / /\ | |/ / | | | | _ __ | | ___ ___ ___
| /| _ || \ | |/| | | '/ _ \ |/ _ / __/ __|
| |\ | | | || |\ \ \ /\ / | | | __/ | /_ _
_| __| |/_| _/ / /||| _|_|_||//
========================================================
AT+CSQAT+CSQ
+CSQ: 14,99
OKAT+QICSGP=1,1,"fast.tmobile.com"
AT+QICSGP=1,1,"fast.tmobile.com"
OKAT+QIACT=1
AT+QIACT=1
OKAT+QIACT?
AT+QIACT?
+QIACT: 1,1,1," "
OKAT+QIOPEN=1,0,"UDP"," ", ,1,1
AT+QIOPEN=1,0,"UDP"," ", ,1,1
OKAT+QISTATE=0,1
AT
+QIOPEN: 0,0
+QISTATE=0,1
+QISTATE: 0,"UDP"," ", ,1,2,1,0,1,"uart1"
OKAT+QISEND=0,95Tem:-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;
AT+QISEND=0,95
>
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;
SEND OKAT+CLOSE=0
Hi,
Remember the at about how to get sensor data? In at.c, line 363. Can you add your UDP part after the end of this part?
memset(at_rsp,0,1536);
memcpy(at_rsp,cmd,strlen(cmd));
sprintf(at_rsp+strlen(at_rsp),"%s\r\n",send_data);
rui_at_response(true, at_rsp, RAK_OK);
First, it can show the sensor data correctly. And you can send this send_data to check.
For now, we just provide the log with RTT of Jlink. USB just out our AT information.
Use AT to send your data. And compare with your code. It must be some code error bug.
Hey @nero, I did that and I am getting the correct sensor data via UDP to my server when I type the AT command however when I just run the user_app.c file it still gives me the sensor data values as 0’s via UDP. So the sensor data values are correctly sent via UDP to the server when I type the AT command however through the sendOk function in the user_app.c file the sensor data values are still 0’s
Also I had a question how do I use an external library with the source code files. Like I tried to compile the zip code of my source files with my .a and .h library file and library header however that failed. So I wanted to know how do I use an external library.
Hi,
OK, it looks like the sendOK function has some bugs… Can you just copy the at part to the sendOK and then try?
As for your file, you can add them to the folder with other files and upload together. We have test this way.