Hi, im not familiar with scripting, i try send to mqtt modbus data.
all work fine
################################ Configuration ################################
# Name of an existing MQTT broker that should be used for publishing
:local broker "MQTT"
# MQTT topic where the message should be published
:local topic "modbuss/Temperature/DS18B20"
#################################### System ###################################
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x1 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x2 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x3 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x4 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x5 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x6 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x7 reg-addr=0x0 as-value once]
:local modbusread [/iot modbus read-holding-registers slave-id=0x08 num-regs=0x8 reg-addr=0x0 as-value once]
:local modbus [:put [($modbusread->"values")]]
#################################### MQTT #####################################
:local message \
"{\"TEMP\":\"$modbus\"}"
###info LOG fails
# :log info "$message";
:put ("[*] Total message size: $[:len $message] bytes")
:put ("[*] Sending message to MQTT broker...")
/iot mqtt publish broker=$broker topic=$topic message=$message
:put ("[*] Done")
and i get - {“TEMP”:“228”};{“TEMP”:“32768”};{“TEMP”:“32768”};{“TEMP”:“227”};{“TEMP”:“229”};{“TEMP”:“32768”};{“TEMP”:“32768”};{“TEMP”:“227”}
how i can get just a simple string like - {228, 32768, 32768, 227, …} ?
and if i understand right from script i can get only whole numbers? than i need make divide at other side not script..
Thanks.
Youre right, i just think read all address from device (8) but "num-regs=0x8" cover address from 1 to 8. as you say all this line was useless and maybe its reason why sometime i get "pool timeout". About TEMP i forget delete, i try get line like (TEMP1:230; TEMP2:220; TEMP3:240... etc) i dont more need this, i want just simple digit string (230, 220,230, ...) all 8 readings.
Your code " "{$[:tostr $modbus]}"[" is right what im searching for now im get "{206;32768;32768;205;205;32768;32768;205}", thanks!