Browse Source

多终端问题修改

master
lihua 5 years ago
parent
commit
718a9bfa84
  1. 37
      LoRaMoteConf.json
  2. 20
      LoRaMoteMock.go
  3. 2
      model.go

37
LoRaMoteConf.json

@ -1,12 +1,29 @@
{
"otaa": true,
"gatewayId": "0102030405060708",
"devEui": "b92fd5d497cfcdbd",
"devAddr": "00530747",
"appKey": "fe80c1f94e6cc62d5d6f72630b43c177",
"appSKey": "2bc9217655160b2c1229b5ecb469242f",
"nwkSKey": "4f862983a453cc50336284fd3c62aba5",
"fPort": 2,
"fCnt": 8,
"freq": 470.3
"current": "mote2",
"configs": {
"mote1": {
"otaa": true,
"gatewayId": "0102030405060708",
"devEui": "b92fd5d497cfcdbd",
"devAddr": "00530747",
"appKey": "fe80c1f94e6cc62d5d6f72630b43c177",
"nwkSKey": "4f862983a453cc50336284fd3c62aba5",
"appSKey": "2bc9217655160b2c1229b5ecb469242f",
"fPort": 2,
"fCnt": 375,
"freq": 470.3
},
"mote2": {
"otaa": false,
"gatewayId": "0102030405060708",
"devEui": "6ef1881ba5541419",
"devAddr": "00c18699",
"appKey": "",
"nwkSKey": "33998df974421457437d986eff739ffa",
"appSKey": "33998df974421457437d986eff739ffa",
"fPort": 2,
"fCnt": 1194,
"freq": 470.3
}
}
}

20
LoRaMoteMock.go

@ -176,6 +176,11 @@ func main() {
mw.currentMoteConf = mw.motesConf.Configs[mw.motesConf.Current]
}
mw.Run()
var confData bytes.Buffer
mw.motesConf.Configs[mw.motesConf.Current] = mw.currentMoteConf
d,_ := json.Marshal(&mw.motesConf)
_ = json.Indent(&confData, d, "", "\t")
_ = ioutil.WriteFile(mw.moteConfFileName,confData.Bytes(),0644)
}
@ -489,7 +494,9 @@ func (mw *MoteMainWindow) HandleData(client paho.Client, message paho.Message){
case lorawan.JoinAccept:
mw.HandleJoinAccept(&phy)
case lorawan.ConfirmedDataDown,lorawan.UnconfirmedDataDown:
mw.HandleDataDown(&phy)
if !mw.HandleDataDown(&phy) {
return
}
default:
fmt.Println("未处理的帧")
}
@ -552,7 +559,7 @@ func (mw *MoteMainWindow) HandleJoinAccept(phy *lorawan.PHYPayload){
}
}
func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload){
func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload) bool{
mpl := phy.MACPayload.(*lorawan.MACPayload)
key := mw.currentMoteConf.AppSKey
if mpl.FPort != nil && *mpl.FPort == 0 {
@ -563,8 +570,11 @@ func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload){
_ = aseKey.UnmarshalText([]byte(key))
err := phy.DecryptFRMPayload(aseKey)
if err == nil {
mw.currentMoteConf.DevAddr = mpl.FHDR.DevAddr.String()
if mw.currentMoteConf.DevAddr == mpl.FHDR.DevAddr.String() {
return true
}
}
return false
}
func (mw *MoteMainWindow) PushData(gatewayEUI string,event string, msg proto.Message) {
@ -674,10 +684,6 @@ func (mw *MoteMainWindow) sendMsg() error{
mw.PushData(mw.currentMoteConf.GatewayId,"up",&frames[j])
}
mw.currentMoteConf.FCnt ++
var confData bytes.Buffer
d,_ := json.Marshal(&mw.currentMoteConf)
_ = json.Indent(&confData, d, "", "\t")
_ = ioutil.WriteFile(mw.moteConfFileName,confData.Bytes(),0644)
return nil
}

2
model.go

@ -22,8 +22,8 @@ type MoteConfig struct {
DevEui string `json:"devEui"`
DevAddr string `json:"devAddr"`
AppKey string `json:"appKey"`
AppSKey string `json:"appSKey"`
NwkSKey string `json:"nwkSKey"`
AppSKey string `json:"appSKey"`
FPort uint8 `json:"fPort"`
FCnt uint32 `json:"fCnt"`
Freq float64 `json:"freq"`

Loading…
Cancel
Save