---
tags: 'Acer'
---
NEMA AC & DC Protocol & Water Meter
===
# LoRaWAN
### Upload Link ( Status Report)
```
typedef struct
{
UINT8 UUID;
UINT8 payloadType=2;
UINT8 startIndex;
UINT8 varNumber;
FLOAT32 variables[varNumber];
} STC_LORAWAN_SEND_PACKAGE;
Format: Port:Data
Port: 12
Data: Byte 0 , UUID , not used in LoRaWAN
Byte 1 , Data Type , always is 2
Byte 2 , Variable Start Index
Byte 3 , Variable Number
Byte 4 ~ 7, Variable 0 in FLOAT32 format [Voltage]
Byte 8 ~ 11, Variable 1 in FLOAT32 format [Current]
Byte 12 ~ 13, CRC16 in Little Endian format
```
### Switch Command
```
01 01 06 00 0C [TIME] [Power] [CRC16]
```
* Time:
灯在打开后会自动关闭,亮灯时间是打开多久的意思。取值范围0-144,表示0-1440分钟。
Time for command duration. Range from 0 ~ 144, that means from 0 ~ 1440 mins.
* Power:
The power for street light. Range from 0 ~ 100 %
亮灯电流。取值范围0-120,表示0-3600m A。这是调整灯的亮度用,比如0m A就可以关灯,1800m A就是50%
的亮度。
### Command Ack
```
01 06 06 00 0C [TIME] [Power] [CRC16]
```
# LoRa P2P
## Query Command
```
P2P_ID 05 03 00 00 00 02 [CRC16]
```
Device only report this command if the ID is themeself.
收到自己的 ID 時才須回報.
## Query Response
```
typedef struct
{
UINT8 UUID;
UINT8 payloadType=2;
UINT8 startIndex;
UINT8 varNumber;
FLOAT32 variables[varNumber];
} STC_LORAWAN_SEND_PACKAGE;
Format: Port:Data
Port: 12
Data: Byte 0 , UUID , not used in LoRaWAN
Byte 1 , Data Type , always is 2
Byte 2 , Variable Start Index
Byte 3 , Variable Number
Byte 4 ~ 7, Variable 0 in FLOAT32 format [Voltage]
Byte 8 ~ 11, Variable 1 in FLOAT32 format [Current]
Byte 12 ~ 13, CRC16 in Little Endian format
```
## Switch Command
```
P2P_ID 05 06 00 0C [TIME] [Power] [CRC16]
```
Device will execute this commnand if the P2P_ID is 0x00 or themself.
收到自己的 P2P_ID 或 0x00 皆須執行開關
* Time:
Time for command duration. Range from 0 ~ 144, that means from 0 ~ 1440 mins.
灯在打开后会自动关闭,亮灯时间是打开多久的意思。取值范围0-144,表示0-1440分钟。
* Power:
The power for street light. Range from 0 ~ 100 %
亮灯电流。取值范围0-120,表示0-3600m A。这是调整灯的亮度用,比如0m A就可以关灯,1800m A就是50%
的亮度。
Byte 12 ~ 13, CRC16 in Little Endian format
## Command Ack
```
P2P_ID 06 06 00 0C [TIME] [Power] [CRC16]
```
## Water Meter
Data Format:
Byte 0 ~ Byte 5 : Bluetooth Module MAC Address
Byte 6 ~ Byte 9 : Meter Value ( FLOAT32 little endian )
Byte 10 ~ Byte11: Modbus CRC16 ( little endian )
Data Format in C structure:
typedef struct
{
UINT8 macAddress[6];
FLOAT32 meterValue;
UINT16 crc;
}
此外,LoRa P2P 的頻率由於怕與 LoRaWAN 有衝突,故我建議設定為 866MHz (
868-2 MHz )
設定 LoRa P2P 模組為 866MHz 的二進位字串為:
0xd1,0x03,0x05,0x00,0x01,0x52,0x48,0x0c,0xc0
# CRC16
```
UINT16 modbus_crc_generate(UINT8 *str,UINT32 len)
{
const UINT16 iCRCGen = 0xA001;
UINT16 iCRCReg = 0xFFFF;
UINT32 i,j;
len&=0xff;
if (len != 0)
{
for(i=0;i<len;i++)
{
iCRCReg ^= (UINT16)str[i];
for(j=0;j<8;j++)
{
if (iCRCReg & 0x01)
{
iCRCReg >>= 1;
iCRCReg ^= iCRCGen;
}
else
{
iCRCReg >>= 1;
}
}
}
}
return iCRCReg;
}
```