Sensors guide
You can find sensors list here:
https://it.confluence.xirgo.com/wiki/spaces/SD/pages/27149009
and if you have access:
You'll find there 7 columns:
DEC value, HEX value and Name
First and second column (DEC and HEX values) is sensor number, by using this number you can save your variables while writing script (as well as using Name). To do that for strings do it like so. First select sensors you want to use for your script from the sensor list (in this case we selected sensor 49152, 49153 and 49154):
While scripting you could use either DEC value, HEX value or name, either way is fine:
Saving string to sensors and publishing
main()
{
while(1)
{
write_buf(49152, 14, "Sensor_STRING1"); //using Decimal value
write_buf(0xC001, 14, "Sensor_STRING2"); //using Hexadecimal value
write_buf(Sensor_STRING3, 14, "Sensor_STRING3"); //using Name
MQTT_PublishSensor(49152); //using Decimal value
MQTT_PublishSensor(0xC001); //using Hexadecimal value
MQTT_PublishSensor(Sensor_STRING3); //using Name
Delay(20000);
}
}
Result will be this:
Same thing is we were to save values into variables. First we select whichever sensor we need:
Then write script like so:
Saving variable to sensor and publishing
main()
{
while(1)
{
set_val(16389, 10); //using Decimal value
set_val(0x4006, 20); //using Hexadecimal value
set_val(Sensor_U32UserDefined2, 30); //using Name
MQTT_PublishSensor(16389); //using Decimal value
MQTT_PublishSensor(0x4006); //using Hexadecimal value
MQTT_PublishSensor(Sensor_U32UserDefined2); //using Name
Delay(20000);
}
}
And the result will be this:
Data types and saving variables into sensors
Note that there are different data types (Data types column). Each data type has a variable value range which is listed bellow:
Type | Storage size | Value range |
|---|---|---|
boolean | 1 byte | 1 or 0 |
uint8 | 1 byte | 0 to 255 |
int8 | 1 byte | -128 to 127 |
uint16 | 2 bytes | 0 to 65,535 |
int16 | 2 bytes | -32,768 to 32,767 |
uint32 | 4 bytes | 0 to 4,294,967,295 |
int32 | 4 bytes | -2,147,483,648 to 2,147,483,647 |
uint64 | 8 bytes | 0 to 18446744073709551615 |
int64 | 8 bytes | -9223372036854775808 to 9223372036854775807 |
float | 4 bytes | ±1.18×10−38 to ±3.4×1038 |
double | 8 bytes | ±2.23×10−308 to ±1.80×10308 |
If you expect your data value to be higher than 255, then you should store that data value to a 16 bit sensor. However if data value is bellow 255, then it can be stored in all the sensors starting from 8 bit sensors.
For example: we know that our variable only goes up to a 100. That means we can store that variable to a 8 bit, 16 bit, 32bit, 64 bit, float and double types. If we know that our variable can only be either 1 or 0, that variable can be stored to any data type. If we know that our variable goes up to 40000, that means our variable can only be stored only to uint16, uint32, int32, uint32, int32, uint64, int64, float and double, but NOT boolean, uint8, int8 and int16, and so on and so fourth.
Set val column
The last column is named set_val, this tells if it's possible to save your own value onto a sensor. If 'No', then you cannot change that value into your own. If 'Yes', then you can change that value into your own. If 'Not recommended', that means we do not recommend to change that value, since our device changes it on it's own and your value will be overwritten by the device.