# Sending Modbus Data to MSSQL

**URL:** <https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671>\
**Category:** General\
**Tags:** database, modbus\
**Created:** [2 February 2022 16:15 UTC](https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671 "2022-02-02T16:15:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joannesskib](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@joannesskib](https://discourse.nodered.org/u/joannesskib)\
**Post date:** [2 February 2022 16:15 UTC](https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671/1 "2022-02-02T16:15:37Z")

</div>

Im trying to send modbus data to MSQL Server, but i dont know where to start. I am inserting query by using insert. But i think i need some function to send modbus data, i just dont know what.  
Picture below for flow.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10a5676d55a82b5e117db7a6e36eae180454eb7d.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 February 2022 14:12 UTC](https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671/2 "2022-02-03T14:12:32Z")

</div>

> [@joannesskib](#):
>
> But i think i need some function to send modbus data, i just dont know what

The first thing to do is inspect the data you get from MODBUS (turn on the debug output in your green group)  
example...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fd54db244617300e8da32b1c82f63a455b8f566.png)

Next, using the path to the values, generate a SQL INSERT e.g...

`INSERT INTO MyTable (timestamp, volts, curr, temp) VALUES(...)` etc

![chrome_TbCAREp3r7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bd14eca4f9656096f16654bf9a85ad2a89cbb04.gif)

### Demo Flow (use CTRL+I to import)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9f7daa0d8c622ffb713c47e64dd0f137f3ca0888.png)

```auto
[{"id":"560772792a1d57f5","type":"inject","z":"85e1791bc0cd6285","name":"ModBus data (faked)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[4,197,0,181,10,84]","payloadType":"bin","x":1760,"y":80,"wires":[["b836b92b879c896b"]]},{"id":"b836b92b879c896b","type":"buffer-parser","z":"85e1791bc0cd6285","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"voltage","offset":0,"length":1,"offsetbit":0,"scale":"/100.0","mask":""},{"type":"int16be","name":"current","offset":2,"length":1,"offsetbit":0,"scale":"/100.0","mask":""},{"type":"int16be","name":"temperature","offset":4,"length":1,"offsetbit":0,"scale":"/100.0","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1760,"y":140,"wires":[["f5a36fb0ccaa2131","d43ddc0cb87a0896"]]},{"id":"f5a36fb0ccaa2131","type":"debug","z":"85e1791bc0cd6285","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1970,"y":140,"wires":[]},{"id":"d43ddc0cb87a0896","type":"MSSQL","z":"85e1791bc0cd6285","mssqlCN":"491533d6adb397ad","name":"","outField":"payload","returnType":"1","throwErrors":1,"query":"INSERT INTO MyTable \r\n (timestamp, volts, curr, temp) \r\nVALUES\r\n (@ts, @v, @c, @t)\r\n","modeOpt":"queryMode","modeOptType":"query","queryOpt":"payload","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"rows","rowsType":"msg","params":[{"output":false,"name":"ts","type":"DateTime","valueType":"datetime","value":"0","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"v","type":"Float","valueType":"msg","value":"payload.voltage","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"c","type":"Float","valueType":"msg","value":"payload.current","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"t","type":"Float","valueType":"msg","value":"payload.temperature","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":1780,"y":240,"wires":[["47cda9cbce627b41"]]},{"id":"47cda9cbce627b41","type":"debug","z":"85e1791bc0cd6285","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1950,"y":240,"wires":[]},{"id":"3ed14c2d7304d8d2","type":"catch","z":"85e1791bc0cd6285","name":"","scope":null,"uncaught":false,"x":1800,"y":340,"wires":[["da510def5f9304eb"]]},{"id":"da510def5f9304eb","type":"debug","z":"85e1791bc0cd6285","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1970,"y":340,"wires":[]},{"id":"491533d6adb397ad","type":"MSSQL-CN","tdsVersion":"7_4","name":"","server":"10.176.1.61","port":"1433","encyption":false,"trustServerCertificate":true,"database":"","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true,"credentials":{"username":"sa","password":"sd1jhb0npb1ptb","domain":""}}]

```

* * *

### Canned Text...

As a new user, you will learn many of the tips and tricks I showed you by watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![joannesskib](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@joannesskib](https://discourse.nodered.org/u/joannesskib)\
**Post date:** [3 February 2022 18:37 UTC](https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671/3 "2022-02-03T18:37:14Z")

</div>

Thanks for the help, i got it to work now!!  
I will definitely watch the videos!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 April 2022 18:37 UTC](https://discourse.nodered.org/t/sending-modbus-data-to-mssql/57671/4 "2022-04-04T18:37:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
