一 ST LoRa开发板接入LoRaWAN服务器-设备端程序开发

本节需要下面四部分内容:

  • 1 LoRa设备端程序

  • 2 LoRa网关配置

  • 3 LoRa服务器配置

  • 4 app拿数据并且可视化

1.1 设备端程序开发

先贴个图,看一下设备端开发板,对,用的是ST最新的LoRa开发板,芯片在屏蔽罩里面。
在这里插入图片描述
这里基本不需要写程序,图形化界面配置即可。
具体做法,装一个crubeMX 6.1.1的软件,安装wl软件包
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
目前这个demo是基于欧洲的频段,可以用crubeMX打开ioc配置文件,重新配置为你自己的频段,如cn470。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里的参数要严格按照你的LoRa服务器里面的配置
在这里插入图片描述
配置OK以后重新生成你自己的工程,用keil打开,烧录程序,用串口调试助手查看打印信息,这里已经入网成功了。
在这里插入图片描述

1.2 增加x-nucleo_IKS01A3传感器开发板

设备要上传一些数据,这里接入ST的传感器开发板,这里也基本不用改程序,就是图形化配置就可以,下面是过程。

在这里插入图片描述

1.2.1 这里选择software packs

在这里插入图片描述
然后打开后进行如下设置:
在这里插入图片描述

1.2.2 传感器目前用的是I2C2,配置好I2C,注意两点,一是速度,二是引脚

在这里插入图片描述
在这里插入图片描述
1.2.3 选择传感器使用的是I2C2
在这里插入图片描述
最终代码:
https://gitee.com/caledonian_study/stlo-ra-node_dh

最后:代码修改的几个点:

sys_conf.h

#define SENSOR_ENABLED  1

sys_sensors.h
数据结构里面增加传感器位置数据的变量

/* USER CODE BEGIN Includes */
#include "iks01a3_env_sensors.h"
#include "iks01a3_motion_sensors.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/**
  * Sensor data parameters
  */
typedef struct
{
  float pressure;         /*!< in mbar */
  float temperature;      /*!< in degC */
  float humidity;         /*!< in % */
  int32_t latitude;       /*!< latitude converted to binary */
  int32_t longitude ;     /*!< longitude converted to binary */
  int16_t altitudeGps;    /*!< in m */
  int16_t altitudeBar ;   /*!< in m * 10 */
  /**more may be added*/
  /* USER CODE BEGIN sensor_t */
IKS01A3_MOTION_SENSOR_Axes_t acceleration;
IKS01A3_MOTION_SENSOR_Axes_t angular_velocity;
IKS01A3_MOTION_SENSOR_Axes_t magnetic_field;
  /* USER CODE END sensor_t */
} sensor_t;

增加使用的开发板

#define X_NUCLEO_IKS01A3 1

运动设备结构体

IKS01A3_MOTION_SENSOR_Capabilities_t MotionCapabilities;

设备初始化


void  EnvSensors_Init(void)
{
  /* USER CODE BEGIN EnvSensors_Init_1 */
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
  IKS01A3_MOTION_SENSOR_Init(IKS01A3_LSM6DSO_0, MOTION_ACCELERO | MOTION_GYRO);

  IKS01A3_MOTION_SENSOR_Init(IKS01A3_LIS2DW12_0, MOTION_ACCELERO);

  IKS01A3_MOTION_SENSOR_Init(IKS01A3_LIS2MDL_0, MOTION_MAGNETO);
	
	
	IKS01A3_MOTION_SENSOR_GetCapabilities(IKS01A3_LSM6DSO_0, &MotionCapabilities);
#endif  /* SENSOR_ENABLED */	
  /* USER CODE END EnvSensors_Init_1 */

读传感器数据的地方增加读运动信息的代码

/* Exported functions --------------------------------------------------------*/
void EnvSensors_Read(sensor_t *sensor_data)
{
  /* USER CODE BEGIN EnvSensors_Read_Last */
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
IKS01A3_MOTION_SENSOR_GetAxes(IKS01A3_LSM6DSO_0, MOTION_ACCELERO, &sensor_data->acceleration);
IKS01A3_MOTION_SENSOR_GetAxes(IKS01A3_LSM6DSO_0, MOTION_GYRO, &sensor_data->angular_velocity);
IKS01A3_MOTION_SENSOR_GetAxes(IKS01A3_LIS2MDL_0, MOTION_MAGNETO, &sensor_data->magnetic_field);
#endif  /* SENSOR_ENABLED */
  /* USER CODE END EnvSensors_Read_Last */
}

设备上行通道数据增加位置信息

static void SendTxData(void)
{

  sensor_t sensor_data;

  EnvSensors_Read(&sensor_data);
 
/*****/
  AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.x>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.x>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.x )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.y>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.y>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.y )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.z>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.z>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.acceleration.z )&0xFF);


  AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.x>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.x>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.x )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.y>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.y>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.y )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.z>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.z>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.angular_velocity.z )&0xFF);
	
	
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.x>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.x>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.x )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.y>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.y>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.y )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.z>>16 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.z>>8 )&0xFF);
	AppData.Buffer[i++] = (uint8_t)((sensor_data.magnetic_field.z )&0xFF);
	
	
	
  humidity    = (uint16_t)(sensor_data.humidity * 10);            /* in %*10     */

  AppData.Buffer[i++] = AppLedStateOn;
  AppData.Buffer[i++] = (uint8_t)((pressure >> 8) & 0xFF);
  AppData.Buffer[i++] = (uint8_t)(pressure & 0xFF);
  AppData.Buffer[i++] = (uint8_t)(temperature & 0xFF);
  AppData.Buffer[i++] = (uint8_t)((humidity >> 8) & 0xFF);
  AppData.Buffer[i++] = (uint8_t)(humidity & 0xFF);
/*****/
  /* USER CODE BEGIN SendTxData_2 */

  /* USER CODE END SendTxData_2 */
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小男孩和胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值