Vicki Downlink Encoder
Use the following script to start controlling Vicki LoRaWAN from your application in settings. Thanks to this script, you can skip understanding the hex device communication protocol of Vicki and go straight to development and testing.
If you will be using Vicki in large installations, we urge you to read the following points from the Device communication protocol document, so you can better understand the device:
1
const decToHex = (integer, shouldAddZero = true) => {
2
let number = (+integer).toString(16).toUpperCase()
3
if( (number.length % 2) > 0 && shouldAddZero ) { number= "0" + number }
4
return number
5
}
6
const dec2hexWithZero = (i) => {
7
return (i+0x10000).toString(16).substr(-4).toUpperCase();
8
}
9
const toHex = (cmdName, cmdId, ...params) => {
10
if(cmdName == "SetOpenWindow") return cmdId.toString(16).padStart(2, '0') + params.reduce((paramString, param) => {
11
return paramString += param
12
}, "")
13
else return cmdId.toString(16).padStart(2, '0') + params.reduce((paramString, param) => {
14
return paramString += param.padStart(2, '0')
15
}, "")
16
}
17
18
19
20
21
const forceClose = () => {
22
return toHex('ForceClose', 0x0B);
23
}
24
25
26
const getAllParams = () => {
27
return toHex('GetAllParams',
28
'14',
29
'16',
30
'17',
31
'12',
32
'13',
33
'18',
34
'19',
35
'15',
36
'1B'
37
);
38
}
39
40
41
const getChildLock = () => {
42
return toHex('GetChildLock', 0x14);
43
}
44
45
46
const getInternalAlgoParams = () => {
47
return toHex('GetInternalAlgoParams', 0x16);
48
}
49
50
51
const getInternalAlgoTdiffParams = () => {
52
return toHex('GetInternalAlgoTdiffParams', 0x17);
53
}
54
55
56
const getJoinRetryPeriod = () => {
57
return toHex('GetJoinRetryPeriod', 0x19);
58
}
59
60
61
const getKeepAliveTime = () => {
62
return toHex('GetKeepAliveTime', 0x12);
63
}
64
65
66
const getOpenWindowParams = () => {
67
return toHex('GetOpenWindowParams', 0x13);
68
}
69
70
71
const getOperationalMode = () => {
72
return toHex('GetOperationalMode', 0x18);
73
}
74
75
76
const getTemperatureRange = () => {
77
return toHex('GetTemperatureRange', 0x15);
78
}
79
80
81
const getUplinkType = () => {
82
return toHex('GetUplinkType', 0x1B);
83
}
84
85
86
const recalibrateMotor = () => {
87
return toHex('RecalibrateMotor', 0x03);
88
}
89
90
91
const receivedKeepaliveCommand = () => {
92
return toHex('ReceivedKeepalive', 0x55);
93
}
94
95
96
const sendCustomHexCommand = (command) => {
97
return toHex('SendCustomHexCommand', command);
98
}
99
100
101
const setChildLock = (enabled) => {
102
let enabledValue = enabled ? 1 : 0;
103
return toHex('SetChildLock', 0x07, decToHex(enabledValue));
104
}
105
106
107
const setInternalAlgoParams = (period, pFirstLast, pNext) => {
108
return toHex('SetInternalAlgoParams', 0x0C, decToHex(period), decToHex(pFirstLast), decToHex(pNext));
109
}
110
111
112
const setInternalAlgoTdiffParams = (cold, warm) => {
113
return toHex('SetInternalAlgoTdiffParams', 0x1A, decToHex(cold), decToHex(warm));
114
}
115
116
117
const setJoinRetryPeriod = (period) => {
118
// period should be passed in minutes
119
let periodToPass = (period * 60) / 5;
120
return toHex('SetJoinRetryPeriod', 0x10, parseInt(periodToPass).toString(16));
121
}
122
123
124
const setKeepAlive = (time) => {
125
return toHex( 'SetKeepAlive', 0x02, parseInt(time).toString(16));
126
}
127
128
129
const setOpenWindow = (enabled, delta, closeTime, motorPosition) => {
130
let enabledValue = enabled ? 1 : 0;
131
let closeTimeValue = parseInt(closeTime) / 5;
132
let motorPositionBin = `000000000000${parseInt(motorPosition, 10).toString(2)}`;
133
motorPositionBin = motorPositionBin.substr(-12);
134
let motorPositionFirstPart = parseInt(motorPositionBin.substr(4), 2, 16);
135
let motorPositionSecondPart = parseInt(motorPositionBin.substr(0, 4), 2, 16);
136
137
return toHex(
138
'SetOpenWindow',
139
0x06,
140
decToHex(enabledValue),
141
decToHex(closeTimeValue),
142
decToHex(motorPositionFirstPart, false),
143
decToHex(motorPositionSecondPart, false),
144
decToHex(delta, false)
145
);
146
}
147
148
149
const setOperationalMode = (mode) => {
150
return toHex( 'SetOperationalMode', 0x0D, mode);
151
}
152
153
154
const setTargetTemperature = (targetTemperature) => {
155
return toHex( 'SetTargetTemperature', 0x0E, decToHex(targetTemperature));
156
}
157
158
159
const setTargetTemperatureAndMotorPosition = (motorPosition, targetTemperature) => {
160
return toHex('SetTargetTemperatureAndMotorPosition', 0x31, dec2hexWithZero(motorPosition), decToHex(targetTemperature))
161
}
162
163
164
const setTemperatureRange = (min, max) => {
165
return toHex( 'SetTemperatureRange', 0x08, decToHex(min), decToHex(max));
166
}
167
168
169
const setUplinkType = (type) => {
170
return toHex( 'SetUplinkType', 0x11, type);
171
}
Copied!
Copy link