当前位置:网站首页>Node data collection and remote flooding transmission of label information
Node data collection and remote flooding transmission of label information
2022-06-29 22:56:00 【I_ love_ hanser_ QAQ】
requirement :
Complete node data collection and remote flooding transmission of label information , With the Sink Nodes connected PC The results can be seen on the ( Tag information 、 Perceived data ). among , Node aware data acquisition includes illumination values 、 Temperature and humidity value , Collection node every 20s Collect primary temperature and humidity 、 Every time 10s Collect a light . The label data read / write control cycle is determined by itself .
notes : Only the key codes are posted below , See my resources for the complete program code ......
The reader node periodically reads the temperature and humidity , light , Label the data and send it to by flood broadcast Sink node ,Sink Node and PC Machine coupling ,Sink After receiving the data packet, upload it to the serial port ,PC On board Python The program processes the serial port data and displays it in UI On the interface .
Screenshot of operation effect (Python Language ) :



Configure component code :
includes Adhoc_APP;
configuration Adhoc_APP { }
implementation
{
components MainC, Adhoc_APPM
, new TimerMilliC() as Timer1, new TimerMilliC() as Timer2,new TimerMilliC() as Timer3,new TimerMilliC() as Timer4
, LedsC
, FloodingC as Route
, BusyWaitMicroC
, RFID_ControlC;
Adhoc_APPM.RFID_Control -> RFID_ControlC;
Adhoc_APPM.Boot -> MainC; // Initialize components
Adhoc_APPM.Leds -> LedsC; // Led Lamp control assembly
Adhoc_APPM.Timer1 -> Timer1; // Timer control assembly
Adhoc_APPM.Timer2 -> Timer2; // Timer control assembly
Adhoc_APPM.Timer3 -> Timer3; // Timer control assembly
Adhoc_APPM.Timer4 -> Timer4;
Adhoc_APPM.BusyWait ->BusyWaitMicroC;
Adhoc_APPM.RControl -> Route;
Adhoc_APPM.Rout_Send -> Route;
Adhoc_APPM.Rout_Receive -> Route;
// Sensors Components
components new SensirionSht11C(), new PhotoSensorC();
Adhoc_APPM.Read_Humi -> SensirionSht11C.Humidity;
Adhoc_APPM.Read_Temp -> SensirionSht11C.Temperature;
Adhoc_APPM.Read_Photo -> PhotoSensorC;
// Uart Components
components SCSuartDBGC;
components ActiveMessageC;
Adhoc_APPM.CommControl -> ActiveMessageC;
Adhoc_APPM.SCSuartSTD -> SCSuartDBGC;
Adhoc_APPM.SCSuartDBG -> SCSuartDBGC;
}Module component code :
module Adhoc_APPM {
uses {
interface Boot;
interface Timer<TMilli> as Timer1;
interface Timer<TMilli> as Timer2;
interface Timer<TMilli> as Timer3;
interface Timer<TMilli> as Timer4;
interface Leds;
interface BusyWait<TMicro, uint16_t>;
interface RFID_Control;
interface StdControl as RControl;
interface AMSend as Rout_Send;
interface Receive as Rout_Receive;
interface SplitControl as CommControl;
}
// Sensor components
uses {
interface Read<uint16_t> as Read_Humi;
interface Read<uint16_t> as Read_Temp;
interface Read<uint16_t> as Read_Photo;
}
// Uart component
uses {
interface StdControl as SCSuartSTD;
interface SCSuartDBG;
}
}
implementation {
message_t TXData;
sensor data
uint16_t myTemp=0xFFFF;
uint16_t myHumi=0xFFFF;
uint16_t myPhoto=0xFFFF;
uint16_t Raw_Temp=0xFFFF; // Raw temp info
uint8_t FUN = 0x00;
uint8_t Data[5] = {0x00,0x00,0x00,0x00,0x00,};
// uint8_t OutputUartMsg[64]; // Serial port output message buff
void calc_SHT_(uint16_t p_humidity ,uint16_t p_temperature);
event void Boot.booted() {
uint8_t mote_id = (uint8_t) TOS_NODE_ID;
if (TOS_NODE_ID != Sink_Addr) // No sink node
{
call Timer3.startOneShot(1000);
call Timer1.startPeriodic(SHT_Interval); // every other 20s Read the temperature and humidity data once
call Timer4.startPeriodic(3000); // every other 7s Read the tag once
}
call RControl.start();
call CommControl.start();
}
event void CommControl.startDone(error_t error) {
call SCSuartSTD.start();
call RFID_Control.start();
}
event void CommControl.stopDone(error_t error) {}
event void Timer3.fired() {
call Timer2.startPeriodic(light_Interval); // every other 10s Read the illumination data once
}
// get sensor data as photo, temp., humi.
// Timer overflow reading illumination data
event void Timer2.fired() {
call Leds.led2Toggle();
call Read_Photo.read();
}
// The timer overflows to read the temperature and humidity
event void Timer1.fired() {
call Leds.led2Toggle();
call Read_Temp.read();
}
// General nodes send to Sink Data collected by the node
task void transmit_frame(){
DataFrameStruct DFS;
call Leds.led1On();
DFS.Temp = myTemp;
DFS.Humi = myHumi;
DFS.Photo = myPhoto;
atomic DFS.FUN = FUN;
// memcpy (DFS.ID, ID, sizeof(ID));
memcpy (DFS.Data, Data, sizeof(Data));
memcpy (call Rout_Send.getPayload(&TXData), &DFS, sizeof(DataFrameStruct));
call Rout_Send.send(Sink_Addr, &TXData, sizeof(DataFrameStruct));
}
// General node data sending completion event
event void Rout_Send.sendDone(message_t* m, error_t err) {
if (err == SUCCESS)
call Leds.led1Off();
}
// sink A node receives a data event sent by a general node
event message_t* Rout_Receive.receive(message_t* msg, void* payload, uint8_t len) {
if (TOS_NODE_ID == Sink_Addr)
{
uint8_t UART_Buff[65], *UART_Buff_p;
uint8_t UART_Buff_len = 0, i;
Route_Msg NWKF;
DataFrameStruct DFS;
UartFrameStruct UFS;
memcpy(&NWKF, call Rout_Send.getPayload(msg), sizeof(Route_Msg));
memcpy(&DFS, NWKF.AppData, sizeof(DataFrameStruct));
UART_Buff_p = (uint8_t *)&UFS;
{
uint32_t Packet_Seq = (uint32_t) NWKF.Sequence;
int16_t OrigiSrcAddr = NWKF.OrigiSrcAddr;
//call SCSuartDBG.UARTSend(UART_Buff, 6);
memcpy (UART_Buff_p+6, (void *)&OrigiSrcAddr, 2);
memcpy (UART_Buff_p+8, (void *)&TOS_NODE_ID, 2);
memcpy (UART_Buff_p+10, (void *)&NWKF.Dst2_for_multihop, 2);
memcpy (UART_Buff_p+12,(void *)&NWKF.Dst3_for_multihop, 2);
memcpy (UART_Buff_p+14,(void *)&Packet_Seq, 4);
memcpy (UART_Buff_p+18,(void *)&DFS.Temp, 2);
memcpy (UART_Buff_p+20,(void *)&DFS.Humi, 2);
memcpy (UART_Buff_p+22,(void *)&DFS.Photo, 2);
memcpy (UART_Buff_p+24,(void *)&DFS.FUN, 1);
// memcpy (UART_Buff_p+25,(void *)&DFS.ID, 8);
memcpy (UART_Buff_p+25,(void *)&DFS.Data, 5);
}
UART_Buff_len = 0;
for ( i=6; i<sizeof(UartFrameStruct) ; i++)
{
UART_Buff[UART_Buff_len++] = UART_Buff_p[i];
}
// call SCSuartDBG.UARTSend(DFS.Data, sizeof(DFS.Data));
// Serial port data transmission
call SCSuartDBG.UARTSend(UART_Buff, UART_Buff_len -13);
call Leds.led0Toggle();
}
return msg;
}
// Read illumination completion event , Send data to sink node
event void Read_Photo.readDone(error_t err, uint16_t val) {
if (err == SUCCESS)
{
myPhoto = val;
atomic FUN = 1;
}
post transmit_frame();
}
// Read temperature completion event , Prepare to read humidity
event void Read_Temp.readDone(error_t err, uint16_t val) {
if (err == SUCCESS)
Raw_Temp = val;
call Read_Humi.read();
}
// Read humidity completion event , Send data to sink node
event void Read_Humi.readDone(error_t err, uint16_t val) {
if (err == SUCCESS && Raw_Temp!=0xFFFF)
{
calc_SHT_(val, Raw_Temp);
atomic FUN = 2;
}
post transmit_frame();
}
// Cyclic redundancy of temperature and humidity , Get the real value
void calc_SHT_(uint16_t p_humidity ,uint16_t p_temperature)
//----------------------------------------------------------------------------------------
// calculates temperature [C] and humidity [%RH]
// input : humi [Ticks] (12 bit)
// temp [Ticks] (14 bit)
// output: humi [%RH]
// temp [C]
{
const float C1=-4.0; // for 12 Bit
const float C2= 0.0405; // for 12 Bit
const float C3=-0.0000028; // for 12 Bit
const float T_1=0.01; // for 14 Bit @ 5V
const float T_2=0.00008; // for 14 Bit @ 5V
float rh_lin; // rh_lin: Humidity linear
float rh_true; // rh_true: Temperature compensated humidity
float t_C; // t_C : Temperature [C]
float rh=(float)p_humidity; // rh: Humidity [Ticks] 12 Bit
float t=(float)p_temperature; // t: Temperature [Ticks] 14 Bit
t_C=t*0.01 - 40; //calc. Temperature from ticks to [C]
rh_lin=C3*rh*rh + C2*rh + C1; //calc. Humidity from ticks to [%RH]
rh_true=(t_C-25)*(T_1+T_2*rh)+rh_lin; //calc. Temperature compensated humidity [%RH]
if(rh_true>100)rh_true=100; //cut if the value is outside of
if(rh_true<0.1)rh_true=0.1; //the physical possible range
atomic myTemp=(uint16_t)t_C; //return temperature [C]
atomic myHumi=(uint16_t)rh_true; //return humidity[%RH]
}
//
// obtain 15693ID Send to when finished Sink node
async event void RFID_Control.GetID_15693_Done (char status, uint8_t *buff, char size){
// memcpy(ID, buff, 8);
// atomic FUN = 3;
// post transmit_frame();
// call RFID_Control.RData_15693(block);
}
// obtain 15693 After the tag data is completed, it is sent to Sink node
async event void RFID_Control.RData_15693_Done (char status, uint8_t *buff, char size){
call SCSuartDBG.UARTSend(buff, 5);
memcpy(Data, buff, 5);
atomic FUN = 3;
post transmit_frame();
}
// Read tag data timer
event void Timer4.fired() {
call RFID_Control.RData_15693 (5);
}
async event void RFID_Control.GetID_14443A_Done(char status, uint8_t *buff, char size) {}
async event void RFID_Control.WData_15693_Done(char status){}
}Python Program code :
Server.py( The main program ):
from PySide2.QtCore import QFile # Import file classes
from PySide2.QtWidgets import QApplication # Import QtWidgets modular
from PySide2.QtUiTools import QUiLoader # load UI file
import threading # Thread module
import serial # Import the serial port module
from Receive import * # Import receiving data module ( user )
# Configure serial port
portx = "COM3"
bps = 57600
# timeout ,None: Always wait for the operation ,0 To return the requested result immediately , Other values are wait timeout ( The unit is in seconds )
timex = None
ser = serial.Serial(portx, bps, timeout=timex) # Turn on serial communication
class Software:
def __init__(self):
# Load from file UI Definition
qfile_Server = QFile("UI/software.ui")
qfile_Server.open(QFile.ReadOnly)
qfile_Server.close()
# from UI Dynamic in definition Create a corresponding window object
self.ui = QUiLoader().load(qfile_Server)
# Button bound event
self.ui.openButton.clicked.connect(self.open)
self.ui.closeButton.clicked.connect(self.close)
self.ui.ClearButton.clicked.connect(self.clear)
def open(self): # Turn it on
self.ui.openButton.setEnabled(False)
self.ui.closeButton.setEnabled(True)
self.ui.ClearButton.setEnabled(True)
def close(self): # To turn it off
self.ui.openButton.setEnabled(True)
self.ui.closeButton.setEnabled(False)
self.ui.ClearButton.setEnabled(False)
self.ui.Tempture.setText("")
self.ui.Humi.setText("")
self.ui.Photo.setText("")
self.ui.Data.setText("")
self.ui.Frame.clear()
def clear(self): # Clear the text browsing box
self.ui.Frame.clear()
# Instantiate window program
app = QApplication([])
software = Software()
software.ui.show()
# Set accept data daemon thread
receivethread = threading.Thread(
target=lambda: receive(software, ser))
receivethread.setDaemon(True)
receivethread.start()
# Loop execution
app.exec_()
Receive.py( Receiving module ) :
from AttributeStruct import * # Data structure module ( user )
import struct # Byte stream unpacking module
def receive(software, ser): # Receiving thread
while(True):
if software.ui.closeButton.isEnabled(): # If it has been turned on
Frame = ser.read(24) # receive 24B data
# Keep the valid fields of the received data frame
Attributes_set(Frame[0], Frame[2], Frame[8], Frame[12], Frame[14],
Frame[16:18], Frame[18], Frame[19], Frame[20:])
# Process the received data frame data
Attributes['Photo'] = struct.unpack('H', Attributes['Photo'])[0]
Attributes['FrameType'] = FrameType_rename(Attributes['FrameType'])
Attributes['CardData'] = CardData_to_string(Attributes['CardData'])
# to update UI Interface
updateUI(software, Attributes)
def updateUI(software, Attributes): # to update UI Interface
software.ui.Tempture.setText(str(Attributes['tempture'])) # Update temperature
software.ui.Humi.setText(str(Attributes['Humi'])) # Update humidity
software.ui.Photo.setText(str(Attributes['Photo'])) # Update lighting
# Update text browsing box
if str(Attributes['CardData']) != 'None': # Tag data not read
software.ui.Data.setText(' ' + str(Attributes['CardData']))
else: # Read tag data
software.ui.Data.setText('')
software.ui.Frame.append('OrigiSrcAddr:' + str(Attributes['OrigiSrcAddr']) + ';DestAddr:' + str(
Attributes['DestAddr']) + ';Seq:' + str(Attributes['Seq']))
software.ui.Frame.ensureCursorVisible()
if str(Attributes['FrameType']) == ' Read the light data ':
software.ui.Frame.append(
'Photo:' + str(Attributes['Photo']) + 'LX; FrameType:' + str(Attributes['FrameType']))
elif str(Attributes['FrameType']) == ' Read temperature and humidity data ':
software.ui.Frame.append('Tempture:' + str(Attributes['tempture']) + '℃; Humi:' + str(Attributes['Humi']) + '%rh;'
+ 'FrameType:' + str(Attributes['FrameType']))
elif str(Attributes['FrameType']) == ' Read label information ':
software.ui.Frame.append('CardData:' + str(Attributes['CardData'])
+ ';FrameType:' + str(Attributes['FrameType']))
software.ui.Frame.ensureCursorVisible()AttributesStruct.py( Data structure module ):
import struct # Byte stream unpacking module
# Receive data structure
Attributes = {
'OrigiSrcAddr': 0x00, # source address ( Reader address )
'DestAddr': 0x00, # Destination address (sink Address )
'Seq': 0x00, # The serial number of the packet
'tempture': 0xFF, # Temperature data
'Humi': 0xFF, # Humidity data
'Photo': b'\xFF\xFF', # Lighting data
'Error': 0x00, # Whether the tag is read successfully (0: success , 2: Failure )
'CardData': b'\xFF\xFF\xFF\xFF', # Tag information
'FrameType': 0x00, # Data frame type (1: light ,2: Temperature and humidity ,3: Tag information )
}
def Attributes_set(OrigiSrcAddr, DestAddr, Seq, tempture, Humi, Photo, FrameType, Error, CardData): # Update data structure
Attributes['OrigiSrcAddr'] = OrigiSrcAddr
Attributes['DestAddr'] = DestAddr
Attributes['Seq'] = Seq
Attributes['tempture'] = tempture
Attributes['Humi'] = Humi
Attributes['Photo'] = Photo
Attributes['FrameType'] = FrameType
Attributes['Error'] = Error
Attributes['CardData'] = CardData
return Attributes
def FrameType_rename(FrameType): # Data frame type
if FrameType == 1:
return ' Read the light data '
elif FrameType == 2:
return ' Read temperature and humidity data '
elif FrameType == 3:
return ' Read label information '
def CardData_to_string(CardData): # Convert label data to string ( Byte stream converted to integer )
CardData = struct.unpack('4B', CardData)
if (Attributes['Error'] == 0): # If the tag is read successfully
string = ""
for i in range(0, len(CardData)):
if CardData[i] > 9:
string += str(chr(CardData[i])) + ' '
else:
string += str(CardData[i]) + ' '
return string
else: # Failed to read label data
return 'None'
边栏推荐
- 什么是IGMP?IGMP与ICMP有啥区别?
- The soft youth under the blessing of devcloud makes education "smart" in the cloud
- The third day
- Wireshark data analysis and forensics information pacapng
- [proteus simulation] digital tube display of stepping motor speed
- 详细聊聊MySQL中auto_increment有什么作用
- Touch key and key control corresponding LED status reversal
- R & D test time ratio, bug data analysis
- 英语没学好到底能不能做coder,别再纠结了先学起来
- VS2013如何让编写的程序在其它电脑上面也能运行
猜你喜欢

NRM explanation

Gnawing down the big bone - sorting (I)

剑指 Offer 38. 字符串的排列

开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开

写论文工具:LaTex在线网站

地方/园区如何做好产业分析?

Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04

AI场景存储优化:云知声超算平台基于 JuiceFS 的存储实践

Unicom warehousing | all Unicom companies that need to sell their products need to enter the general warehouse first

2022年第一季度保险服务数字化跟踪分析
随机推荐
论文阅读《Large-Scale Direct SLAM with Stereo Cameras》
Optional类的高级使用
Mysql database: use the show profile command to analyze performance
80-Redis详解
LeetCode85+105+114+124
wirehark数据分析与取证infiltration.pacapng
什么是IGMP?IGMP与ICMP有啥区别?
Discussion on distributed unique ID generation scheme
STM32基础知识点
AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
0. grpc environment setup
Open source the Ernie tiny lightweight technology of "Wenxin big model", which is accurate and fast, with full effect
利用kubernetes中的leader选举机制来完成自己的HA应用
股票开户安全吗?上海股票开户。
Ansible自动化运维
Unicom warehousing | all Unicom companies that need to sell their products need to enter the general warehouse first
The soft youth under the blessing of devcloud makes education "smart" in the cloud
【Proteus仿真】步进电机转速数码管显示
触摸按键与按键控制对应的LED状态翻转
Mysql database: storage engine