# Reading Modbus and Writing to Database

**URL:** https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284
**Category:** General
**Tags:** modbus
**Created:** [16 February 2023 09:30 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284 "2023-02-16T09:30:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Seymi](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Seymi](https://discourse.nodered.org/u/Seymi)
#### Post date: [16 February 2023 09:30 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/1 "2023-02-16T09:30:20Z")

</div>

I am getting the data in this format but I can't write this data format to a database. I must split these datas for writing to database as 1 or 0 format. Which function code should i use to format data and write it to database.

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 February 2023 10:37 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/2 "2023-02-16T10:37:57Z")

</div>

Welcome to the forum @Seymi

Is this a college assignment?

---

<div class="post-metadata">

### Author: ![Seymi](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Seymi](https://discourse.nodered.org/u/Seymi)
#### Post date: [16 February 2023 10:54 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/3 "2023-02-16T10:54:46Z")

</div>

No I am an intern in a factory this is my assignment.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 February 2023 11:09 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/4 "2023-02-16T11:09:08Z")

</div>

Are you sure that you just need to send a set of true/false values to the database?  
If so, then what database type is it and what are the fields of the table it has to be written to?

---

<div class="post-metadata">

### Author: ![Seymi](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Seymi](https://discourse.nodered.org/u/Seymi)
#### Post date: [16 February 2023 11:11 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/5 "2023-02-16T11:11:47Z")

</div>

Those values are indicators for the machine status. If first bit is 1 then machine 1 is ON. If second bit is 0 then machine 2 is OFF.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 February 2023 11:13 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/6 "2023-02-16T11:13:38Z")

</div>

OK, so what is the answer to my other question?

> [@Colin](#):
>
> what database type is it and what are the fields of the table it has to be written to

---

<div class="post-metadata">

### Author: ![Seymi](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@Seymi](https://discourse.nodered.org/u/Seymi)
#### Post date: [16 February 2023 11:24 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/7 "2023-02-16T11:24:45Z")

</div>

The table has DT (DateTime), SENSOR(Int) and SENSOR\_VALUE(Int) fields. The database is MariaDB.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 February 2023 13:23 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/8 "2023-02-16T13:23:44Z")

</div>

Is the sensor the index into the array?  
So is that one row in the table for each element in the array?

---

<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: [17 April 2023 13:24 UTC](https://discourse.nodered.org/t/reading-modbus-and-writing-to-database/75284/9 "2023-04-17T13:24:34Z")

</div>

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