-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrfp2mqtt.go
1806 lines (1560 loc) · 58.6 KB
/
rfp2mqtt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* File: /home/jean-yves/go/src/rfp2mqtt/rfp2mqtt.go
* Project: /home/jean-yves/go/src/rfp2mqtt
* Created Date: Monday 23 March 2020
* Author: Jean-Yves Vern
* -----
* Last Modified: Friday 28 August 2020 17:02:16
* Modified By: the developer formerly known as Jean-Yves Vern at <[email protected]>
* -----
* Copyright (c) 2020 Company undefined
* -----
* HISTORY:
*/
package main
/**
* Gateway package RFPlayer (RFP1000) to MQTT
* Author : Jean-Yves Vern
* Date : 28 mars 2019
*
* // ? Handle name and directory of configuration file in command line
*
* // ! Start daemon mode if set in config : https://github.com/VividCortex/godaemon
* // ! Handle SIGTERM signal and CTRL/C : https://medium.com/@edwardpie/handling-os-signals-guarantees-graceful-degradation-in-go-cb57d604d39d
* // ! Read certificate file from filesystem
*
* Update : 31 décembre 2019
* - Ajout du support de connexion en TLS au broker (https://opium.io/blog/mqtt-in-go/)
*
* Update : 9 mai 2021
* - Ajout du support de commande x2d
* - Ajout de la donnée subtype dans le message json
*/
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/binary"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
mqtt "github.com/eclipse/paho.mqtt.golang" // Communication with MQTT broker
cache "github.com/patrickmn/go-cache" // In memory structure to handle actuators and sensors
log "github.com/sirupsen/logrus" // For log facility
conf "github.com/spf13/viper" // Configuration handling
rfp "github.com/jacobsa/go-serial/serial" // Communication with rfplayer dongle
)
/**
* Binary Data[] Size Type Remark
* FrameType 1 byte Value = 0
* DataFlag 1 byte 0: 433Mhz, 1: 868Mhz
* RFLevel 1 int8 Unit : dB (high signal :-40dB to low : -110dB)
* FloorNoise 1 init : dB (high signal :-40dB to low : -110dB)
* Protocol 1 byte below
* InfosType 1 byte below
*/
/* ******************************************************************** */
/**
* Binary Data[] Size Type Remark
* FrameType 1 byte Value = 0
* DataFlag 1 byte 0: 433Mhz, 1: 868Mhz
* RFLevel 1 int8 Unit : dB (high signal :-40dB to low : -110dB)
* FloorNoise 1 int8 Unit : dB (high signal :-40dB to low : -110dB)
* RFQuality 1 byte
* Protocol 1 byte See below
* InfosType 1 byte See below
* Infos[0?9] 20 Signed or uint16
* upon context LSB first. Define provided data by the device
*/
const sync1ContainerConstant byte = 'Z'
const sync2ContainerConstant byte = 'I'
const qualifierASCIIInterpretor byte = '+'
//const QualifierASCIIConstant2 byte = ':'
const asciiContainerMask byte = 0x40
const regularIncomingBinaryUSBFrameType = 0
const regularIncomngRfBinaryUSBFrameType = 0
const rflinkIncomingBinaryUSBFrameType = 1
const rflinkIncomingRfBinaryUSBFrameType = 1
const sourceDest433868 = 1
const sendActionOFF = 0
const sendActionON = 1
const sendActionDIM = 2
const sendActionBRIGHT = 3
const sendActionALLOFF = 4
const sendActionALLON = 5
const sendActionASSOC = 6
const sendActionDISSOC = 7
const sendActionASSOCOFF = 8
const sendActionDISSOCOFF = 9
/* ***************************************** */
const sendUNDEFINEDProtocol = 0
const sendVISONICProtocol433 = 1
const sendVISONICProtocol868 = 2
const sendCHACONProtocol433 = 3
const sendDOMIAProtocol433 = 4
const sendX10Protocol433 = 5
const sendX2DProtocol433 = 6
const sendX2DProtocol868 = 7
const sendX2DSHUTTERProtocol868 = 8
const sendX2DHAELECProtocol868 = 9
const sendX2DHAGASOILProtocol868 = 10
const sendSOMFYProtocol433 = 11
const sendBLYSSProtocol433 = 12
const sendPARROT = 13
const sendOREGONProtocol433X = 14 /* not reachable by API */
const sendOWL433X = 15 /* not reachable by API */
const sendKD101Protocol433 = 16 /* 32 bits ID */
const sendDIGIMAXTS10Protocol433 = 17 /* deprecated */
const sendOREGONProtocolV1433 = 18 /* not reachable by API */
const sendOREGONProtocolV2433 = 19 /* not reachable by API */
const sendOREGONProtocolV3433 = 20 /* not reachable by API */
const sendTIC433 = 21 /* not reachable by API */
const sendFS20868 = 22
/* ***************************************** */
const receivedProtocolUNDEFINED = 0
const receivedProtocolX10 = 1
const receivedProtocolVISONIC = 2
const receivedProtocolBLYSS = 3
const receivedProtocolCHACON = 4
const receivedProtocolOREGON = 5
const receivedProtocolDOMIA = 6
const receivedProtocolOWL = 7
const receivedProtocolX2D = 8
const receivedProtocolRFY = 9
const receivedProtocolKD101 = 10
const receivedProtocolPARROT = 11
const receivedProtocolDIGIMAX = 12 /* deprecated */
const receivedProtocolTIC = 13
const receivedProtocolFS20 = 14
const receivedProtocolJAMMING = 15
const regularIncomingRFBinaryUSBFrameInfosWordsNumber = 10
const infosType0 = 0
const infosType1 = 1
const infosType2 = 2
const infosType3 = 3
const infosType4 = 4
const infosType5 = 5
const infosType6 = 6
const infosType7 = 7
const infosType8 = 8
const infosType9 = 9
const infosType10 = 10
const infosType11 = 11
const infosType12 = 12 /* deprecated */
const infosType13 = 13
const infosType14 = 14
const infosType15 = 15
// Sensor : Struct for sensors
type Sensor struct {
Ref string
SubType string
Name string
Protocol string
Topic string
}
type sensors []Sensor
type payloadTH struct {
T string
H string
}
type messageContainerHeader struct {
sync1 byte
sync2 byte
sourceDestQualifier byte
qualifierOrLenLsb byte
qualifierOrLenMsb byte
}
type regularIncomingBinaryUSBFrame struct { // public binary API USB to RF frame Sending
frameType byte
cluster byte // set 0 by default. Cluster destination.
protocol byte
action byte
ID uint32 // LSB first. Little endian, mostly 1 byte is used
dimValue byte
burst byte
qualifier byte
reserved2 byte // set 0
}
type incomingRFInfosType0 struct { // used by X10 / Domia Lite protocols
subType uint16
id uint16
}
type incomingRFInfosType1 struct { // Used by X10 (32 bits ID) and CHACON
subType uint16
idLsb uint16
idMsb uint16
}
type incomingRFInfosType2 struct { // Used by VISONIC /Focus/Atlantic/Meian Tech
subType uint16
idLsb uint16
idMsb uint16
qualifier uint16
}
type incomingRFInfosType3 struct { // Used by RFY PROTOCOL
subType uint16
idLsb uint16
idMsb uint16
qualifier uint16
}
type incomingRFInfosType4 struct { // Used by Scientific Oregon protocol ( thermo/hygro sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
temp int16 // UNIT: 1/10 of degree Celsius
hygro uint16 // 0...100 UNIT: %
}
type incomingRFInfosType5 struct { // Used by Scientific Oregon protocol ( Atmospheric pressure sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
temp int16 // UNIT: 1/10 of degree Celsius
hygro uint16 // 0...100 UNIT: %
pressure uint16 // UNIT: hPa
}
type incomingRFInfosType6 struct { // Used by Scientific Oregon protocol (Wind sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
speed uint16 // Averaged Wind speed (Unit : 1/10 m/s, e.g. 213 means 21.3m/s)
direction uint16 // Wind direction 0-359° (Unit : angular degrees)
}
type incomingRFInfosType7 struct { // Used by Scientific Oregon protocol ( UV sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
light uint16 // UV index 1..10 (Unit : -)
}
type incomingRFInfosType8 struct { // Used by OWL ( Energy/power sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
energyLsb uint16 // LSB: energy measured since the RESET of the device (32 bits value). Unit : Wh
energyMsb uint16 // MSB: energy measured since the RESET of the device (32 bits value). Unit : Wh
power uint16 // Instantaneous measured (total)power. Unit : W (with U=230V, P=P1+P2+P3))
powerI1 uint16 // Instantaneous measured at input 1 power. Unit : W (with U=230V, P1=UxI1)
powerI2 uint16 // Instantaneous measured at input 2 power. Unit : W (with U=230V, P2=UxI2)
powerI3 uint16 // Instantaneous measured at input 3 power. Unit : W (with U=230V, P2=UxI3)
}
type incomingRFInfosType9 struct { // Used by OREGON ( Rain sensors)
subType uint16
idPHY uint16
idChannel uint16
qualifier uint16
totalRainLsb uint16 // LSB: rain measured since the RESET of the device (32 bits value). Unit : 0.1 mm
totalRainMsb uint16 // MSB: rain measured since the RESET of the device
rain uint16 // Instantaneous measured rain. Unit : 0.01 mm/h
}
type incomingRFInfosType10 struct { // Used by Thermostats X2D protocol
subType uint16
idLsb uint16
idMsb uint16
qualifier uint16 // D0 : Tamper Flag, D1: Alarm Flag, D2: Low Batt Flag, D3: Supervisor Frame, D4: Test D6:7 : X2D variant
function uint16
mode uint16 //
data [4]uint16 // provision
}
type incomingRFInfosType11 struct { // Used by Alarm/remote control devices X2D protocol
subType uint16
idLsb uint16
idMsb uint16
qualifier uint16 // D0 : Tamper Flag, D1: Alarm Flag, D2: Low Batt Flag, D3: Supervisor Frame, D4: Test D6:7 : X2D variant
reserved1 uint16
reserved2 uint16
data [4]uint16 // provision
}
type incomingRFInfosType12 struct { // Used by DIGIMAX TS10 protocol // deprecated
subType uint16
idLsb uint16
idMsb uint16
qualifier uint16
temp int16 // UNIT: 1/10 of degree
setPoint int16 // UNIT: 1/10 of degree
}
type incomingRFInfosType13 struct { // Used by Cartelectronic TIC/Pulses devices (Teleinfo/TeleCounters)
subtype uint16 // subtype/version
idLsb uint16
idMsb uint16
qualifier uint16 // D8-15: idMsb2 D0:7 : flags
infos uint16 // state/contract type
counter1Lsb uint16
counter1Msb uint16
counter2Lsb uint16
counter2Msb uint16
apparentPower uint16
}
type incomingRFInfosType14 struct { // Used by FS20. Same file as INCOMING_RF_INFOS_TYPE2
subtype uint16
idLsb uint16
idMsb uint16
qualifier uint16
}
type incomingRFInfosType15 struct { // Used by JAMMING (idem Type1)
subType uint16
idLsb uint16
idMsb uint16
}
var cmqtt mqtt.Client
var cmqttOpts mqtt.ClientOptions
var b bytes.Buffer
var ch chan []byte
// var insecure *bool
var rfpConfig rfp.OpenOptions
var rfpPort io.ReadWriteCloser
var errGlobal error
var sensorsNameCache *cache.Cache // Indexed by Id
var sensorsTopicCache *cache.Cache // Indexed by Id
var actuatorsIDCache *cache.Cache // Indexed by Name
var actuatorsTopicCache *cache.Cache // Indexed by Name
var actuatorsCommandCache *cache.Cache // Indexed by Name
var actuatorsProtocolCache *cache.Cache // Indexed by Name
var iCompteur int
var iWait2Send int
var flagConfigFile string
// Config : Internal struct type for config datas described in config.yml
type Config struct {
Rfplayer struct {
WaitToSend int `yaml:"waittosend"`
Port string `yaml:"port"`
Timeout int `yaml:"timeout"`
Minread int `yaml:"minread"`
RTSCTSFlowControl bool `yaml:"rtsctsflowcontrol"`
Initialisation []struct {
Cmd string `yaml:"cmd"`
} `yaml:"initialisation"`
} `yaml:"rfplayer"`
Brockermqtt struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Protocol string `yaml:"protocol"`
Address string `yaml:"address"`
Port int `yaml:"port"`
Certfile string `yaml:"certfile"`
Insecure bool `yaml:"insecure"`
TopicRoot string `yaml:"topicroot"`
} `yaml:"brockermqtt"`
Log struct {
Format string `yaml:"format"`
Output string `yaml:"output"`
Level string `yaml:"level"`
} `yaml:"log"`
Sensors []struct {
ID string `yaml:"id"`
Name string `yaml:"nom"`
Ref string `yaml:"ref,omitempty"`
Topic string `yaml:"topic,omitempty"`
} `yaml:"sensors"`
Actuators []struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Protocol string `yaml:"protocol"`
Topic string `yaml:"topic"`
Command string `yaml:"command"`
} `yaml:"actuators"`
}
var config Config
/**
* Compute an unsigned 32 bits integer from unsigned 16 bits integer
*/
func touint32(msb uint16, lsb uint16) (u32 uint32) {
u32 = uint32(msb) << 16
u32 = u32 + uint32(lsb)
log.Debug("touint32: ", msb, " / ", lsb, " => ", u32)
return u32
}
/**
* Compute an unsigned 32 bits integer from an ascii deviceIO ie X10 code (A1, C2, ...)
*/
func atobDeviceID(dID string) (u32 uint32) {
uLettre := dID[0] - 'A'
// sChiffre := dID[1:len(dID)]
sChiffre := dID[1:]
uChiffre, err := strconv.ParseUint(sChiffre, 10, 32)
if err != nil {
return 0
}
u32 = (uint32(uLettre) * 16) + uint32(uChiffre) - 1
log.Debug("atobDeviceID: ", dID, " => ", u32, " => character: ", string(dID[0]), ", number: ", uChiffre)
return u32
}
/**
* Function that return a string 0 or 1 corresponding to the bit npar of byte bpar
*/
func testBit(bpar byte, npar int) string {
if bpar&(1<<uint8(npar)) != 0 {
return "1"
}
return "0"
}
/**
* Decode a message from RFPlayer
*/
func decode(l int, m []byte) {
var jsonString string
timecodeString := time.Now().Format(time.RFC3339)
sensor := Sensor{}
log.Debug("RFLevel=", int8(m[8]), ", FloorNoise=", int8(m[9]), ", RFQuality=", m[10], ", Protocol=", m[11], ", InfosType=", m[12])
switch m[12] {
case infosType0:
log.Debug(", X10, DOMIA_LITE, PARROT")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", Id=", binary.LittleEndian.Uint32(m[15:]))
sensor.Ref = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Protocol = "X10"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/x10"
}
log.Debug(", topic=", sensor.Topic)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType1:
log.Debug(", CHACON ...")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", Id=", binary.LittleEndian.Uint32(m[15:]))
sensor.Ref = "1-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "CHACON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/chacon"
}
log.Debug(", topic=", sensor.Topic)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType2:
log.Debug(", VISONIC")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", Id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
sensor.Ref = "2-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "VISONIC"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/visonic"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"ftamper\": \"" + testBit(m[19], 0) // tamper flag
jsonString = jsonString + "\" , \"falarm\": \"" + testBit(m[19], 1) // alarm flag
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 2) // low batt flag
jsonString = jsonString + "\" , \"falive\": \"" + testBit(m[19], 3) // supervisor message flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType3:
log.Debug(", RTS")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", Id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
sensor.Ref = "3-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "RTS"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/rts"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType4:
log.Debug(", OREGON Thermo/Hygro")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", temp=", int16(binary.LittleEndian.Uint16(m[21:])))
log.Debug(", hygro=", binary.LittleEndian.Uint16(m[23:]))
sensor.Ref = "4-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OREGON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/th"
}
log.Debug(", topic=", sensor.Topic)
tempString := strconv.FormatFloat(float64(uint64(binary.LittleEndian.Uint16(m[21:])))*0.1, 'f', 1, 64)
humiString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[23:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"t\": \"" + tempString
jsonString = jsonString + "\" , \"h\": \"" + humiString
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
// } else {
// log.Info("RFLevel=", int8(m[8]), ", FloorNoise=", int8(m[9]), ", RFQuality=", m[10], ", Protocol=", m[11], ", InfosType=", m[12])
// log.Info("Topic problem : topic=>", sensor.Topic, "<, len=", len(topicSplit), ", Sensor Ref:>", sensor.Ref, "<")
// }
case infosType5:
log.Debug(", OREGON Atmo pressure")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", temp=", int16(binary.LittleEndian.Uint16(m[21:])))
log.Debug(", hygro=", binary.LittleEndian.Uint16(m[23:]))
log.Debug(", pressure=", binary.LittleEndian.Uint16(m[25:]))
sensor.Ref = "5-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OREGON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/thpa"
}
log.Debug(", topic=", sensor.Topic)
tempString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[21:])), 10)
humiString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[23:])), 10)
pressureString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[25:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"t\": \"" + tempString
jsonString = jsonString + "\" , \"h\": \"" + humiString
jsonString = jsonString + "\" , \"p\": \"" + pressureString
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType6:
log.Debug(", OREGON Wind")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", speed=", binary.LittleEndian.Uint16(m[21:]))
log.Debug(", direction=", binary.LittleEndian.Uint16(m[23:]))
sensor.Ref = "6-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OREGON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/wind"
}
log.Debug(", topic=", sensor.Topic)
speedString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[21:])), 10)
directionString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[23:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"s\": \"" + speedString
jsonString = jsonString + "\" , \"d\": \"" + directionString
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType7:
log.Debug(", OREGON UV")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", light=", binary.LittleEndian.Uint16(m[21:]))
sensor.Ref = "7-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OREGON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/uv"
}
log.Debug(", topic=", sensor.Topic)
lightString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[21:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"l\": \"" + lightString
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType8:
log.Debug(", OWL")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", energy=", binary.LittleEndian.Uint32(m[21:]))
log.Debug(", power=", binary.LittleEndian.Uint32(m[25:]))
log.Debug(", powerI1=", binary.LittleEndian.Uint32(m[27:]))
log.Debug(", powerI2=", binary.LittleEndian.Uint32(m[29:]))
log.Debug(", powerI3=", binary.LittleEndian.Uint32(m[31:]))
sensor.Ref = "8-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OWL"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/owl"
}
log.Debug(", topic=", sensor.Topic)
energyString := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[21:])), 10)
powerString := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[25:])), 10)
powerI1String := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[27:])), 10)
powerI2String := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[29:])), 10)
powerI3String := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[31:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"e\": \"" + energyString
jsonString = jsonString + "\" , \"p\": \"" + powerString
jsonString = jsonString + "\" , \"pi1\": \"" + powerI1String
jsonString = jsonString + "\" , \"pi2\": \"" + powerI2String
jsonString = jsonString + "\" , \"pi3\": \"" + powerI3String
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType9:
log.Debug(", OREGON Rain")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", idPHY=", binary.LittleEndian.Uint16(m[15:]))
log.Debug(", idChannel=", binary.LittleEndian.Uint16(m[17:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", totalRain=", binary.LittleEndian.Uint32(m[21:]))
log.Debug(", rain=", binary.LittleEndian.Uint16(m[25:]))
sensor.Ref = "9-" + strconv.FormatUint(uint64(touint32(binary.LittleEndian.Uint16(m[15:]), binary.LittleEndian.Uint16(m[17:]))), 10)
sensor.Protocol = "OREGON"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/rain"
}
log.Debug(", topic=", sensor.Topic)
totalrainString := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[21:])), 10)
rainString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[25:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"tra\": \"" + totalrainString
jsonString = jsonString + "\" , \"ra\": \"" + rainString
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 0) // low batt flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType10:
log.Debug(", X2D Thermostat")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", fonction=", binary.LittleEndian.Uint16(m[21:]))
log.Debug(", mode=", binary.LittleEndian.Uint16(m[23:]))
log.Debug(", data[4]=", binary.LittleEndian.Uint16(m[25:]))
sensor.Ref = "10-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "X2D"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/x2dcontact"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"ftamper\": \"" + testBit(m[19], 0) // tamper flag
jsonString = jsonString + "\" , \"fanomaly\": \"" + testBit(m[19], 1) // anomaly flag
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 2) // low batt flag
jsonString = jsonString + "\" , \"ftestassoc\": \"" + testBit(m[19], 4) // test assoc flag
jsonString = jsonString + "\" , \"fdomestic\": \"" + testBit(m[19], 5) // domestic frame flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType11:
log.Debug(", X2D Shutter")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", reserved1=", binary.LittleEndian.Uint16(m[21:]))
log.Debug(", reserved2=", binary.LittleEndian.Uint16(m[23:]))
log.Debug(", data[4]=", binary.LittleEndian.Uint16(m[25:]))
sensor.Ref = "11-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "X2D"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/x2dshutter"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
log.Debug(", topic=", sensor.Topic)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"ftamper\": \"" + testBit(m[19], 0) // tamper flag
jsonString = jsonString + "\" , \"fanomaly\": \"" + testBit(m[19], 1) // anomaly flag
jsonString = jsonString + "\" , \"flowbatt\": \"" + testBit(m[19], 2) // low batt flag
jsonString = jsonString + "\" , \"ftestassoc\": \"" + testBit(m[19], 4) // test assoc flag
jsonString = jsonString + "\" , \"fdomestic\": \"" + testBit(m[19], 5) // domestic frame flag
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType12:
log.Debug(", deprecated")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", temp=", (int16)(binary.LittleEndian.Uint16(m[21:])))
log.Debug(", setPoint=", (int16)(binary.LittleEndian.Uint16(m[23:])))
sensor.Ref = "12-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "DEPRECATED"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/null"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType13:
log.Debug(", Linky")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
log.Debug(", contractType=", binary.LittleEndian.Uint16(m[21:]))
log.Debug(", setPoint=", (int16)(binary.LittleEndian.Uint16(m[23:])))
log.Debug(", cnt1=", binary.LittleEndian.Uint32(m[25:]))
log.Debug(", cnt2=", binary.LittleEndian.Uint32(m[29:]))
log.Debug(", apparentPower=", binary.LittleEndian.Uint16(m[33:]))
sensor.Ref = "13-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "LINKY"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/linky"
}
log.Debug(", topic=", sensor.Topic)
contracttypeString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[21:])), 10)
setpointString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[23:])), 10)
cnt1String := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[25:])), 10)
cnt2String := strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[29:])), 10)
apparentpowerString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[33:])), 10)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"ct\": \"" + contracttypeString
jsonString = jsonString + "\" , \"sp\": \"" + setpointString
jsonString = jsonString + "\" , \"cnt1\": \"" + cnt1String
jsonString = jsonString + "\" , \"cnt2\": \"" + cnt2String
jsonString = jsonString + "\" , \"ap\": \"" + apparentpowerString
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType14:
log.Debug(", FS20")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", id=", binary.LittleEndian.Uint32(m[15:]))
log.Debug(", qualifier=", binary.LittleEndian.Uint16(m[19:]))
sensor.Ref = "14-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "FS20"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/fs20"
}
log.Debug(", topic=", sensor.Topic)
qualifierString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[19:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"q\": \"" + qualifierString
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
case infosType15:
log.Debug(", JAMMING")
log.Debug(", SubType=", binary.LittleEndian.Uint16(m[13:]))
log.Debug(", Id=", binary.LittleEndian.Uint32(m[15:]))
sensor.Ref = "15-" + strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[15:])), 10)
sensor.Protocol = "JAMMING"
sensor.SubType = strconv.FormatUint(uint64(binary.LittleEndian.Uint32(m[13:])), 10)
sensor.Name = sensorName(sensor.Ref)
sensor.Topic = sensorTopic(sensor.Ref)
if sensor.Topic == "NULL" {
sensor.Topic = conf.GetString("brokermqtt.topicroot") + "/" + sensor.Ref + "/jamming"
}
log.Debug(", topic=", sensor.Topic)
subtypeString := strconv.FormatUint(uint64(binary.LittleEndian.Uint16(m[13:])), 10)
topicSplit := strings.Split(sensor.Topic, "/")
jsonString = "{ \"tc\": \"" + timecodeString
jsonString = jsonString + "\" , \"n\": \"" + topicSplit[1]
jsonString = jsonString + "\" , \"r\": \"" + sensor.Ref
jsonString = jsonString + "\" , \"s\": \"" + subtypeString
jsonString = jsonString + "\" , \"st\": \"" + sensor.SubType
jsonString = jsonString + "\" }"
}
/**
* Send the MQTT message in non blocking way
*/
log.Debug("Publication MQTT jsonString : ", jsonString)
go publish(sensor.Topic, jsonString)
}
/**
* Function the publish a MQTT message with topic t and message d
*/
func publish(t string, d string) {
var token mqtt.Token
if cmqtt.IsConnectionOpen() {
token = cmqtt.Publish(t, 2, false, d)