# Python Script into .JSON file for node red?

**URL:** <https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535>\
**Category:** Developing Nodes\
**Created:** [12 May 2021 10:49 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535 "2021-05-12T10:49:48Z")\
**Posts on this page:** 13\
**Page:** 5

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [30 June 2021 14:19 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/81 "2021-06-30T14:19:05Z")

</div>

In this case with this device, I think you might not need the python script. You could start to try to use the serial node in Node-RED directly. Maybe that will work to get the communication going?

Configure to connect to /dev/ttyUSB0 with the params recommended in the doc

Something like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52b5ff06d960b9ebdee9a3e34415796ff63a392a.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe737b8ea6dd98a32bf88b307c4fdf850bfc369b.png)

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [14 July 2021 13:50 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/82 "2021-07-14T13:50:01Z")

</div>

Thank you for your answer and sorry for my late response, I was sick for a longer time.

I tried what you told me and i got an Error. (while I got the first report in the debug window the serial nodes said "connected")

( I have also a connection problem, but I'm working on that, I think that the device doesn't get enough power so I ordered a USB hub to test it.)

Can you say if this is an error code about false setting or about the faulty connection I have at the moment?

 ![Screenshot 2021-07-14 153618](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59e9230220bfe1314b47c0e73ec5ed24aa3441a7.jpeg)

I thank you in advance!

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [14 July 2021 15:19 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/83 "2021-07-14T15:19:38Z")

</div>

I think that is a port connection problem. When you connect the device, do you then find the port listed in /dev folder? If so, does it go away when you disconnect?  
If I remember from manual correctly you have to start the communication with a specific command. If you send something randomly, it might be the device disconnects the port

What are you sending with the inject node?

PS with correct settings of baudrate, other params etc

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [16 July 2021 10:06 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/84 "2021-07-16T10:06:51Z")

</div>

I got the usb hub and the connection ist now stable, so the power was the problem.  
At first my infect node was "msg.payload = timestamp", but I tried to send different strings like in the SB\_MAVO-USB.pdf mentioned, but I still get the same error "error 008".  
When I send "msg.payload=msg.payload" with the inject node I got no report at all.

 ![Screenshot 2021-07-16 115233](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/6430c4ba8a44d5573e9940460b4d4d3e5e52c77f.jpeg)  
 ![Screenshot 2021-07-16 115754](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea8c15610b5f73e5b0a003d7eef8722ecc617302.jpeg)  
 ![Screenshot 2021-07-16 120615](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e5468c1e76e13df8a9818545e60d7178b210849b.jpeg)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [16 July 2021 10:34 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/85 "2021-07-16T10:34:59Z")

</div>

So a good start, I think the error messages are coming from the device, it is not understanding your command

According to documentation you have to start the communication by sending the string \*IDN? so this is what you have to put into your inject node

Then also as stated in the document you have to add line feed after the command. Check your setting for ”Versand”, ”Zeichen zu Ausgangsnachrichten hinzufugen”, add \n here  
Now try again, if it works you should see a response coming in like IDN GOSSEN …..

Best regards, Walter

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [16 July 2021 11:05 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/86 "2021-07-16T11:05:43Z")

</div>

Thank you!  
So I tried what you said and I still get the same report. Did I do anything wrong ?  
( I also tried \*IDN, \*idn, idn?, IDN?, idn and IDN, but same report

 ![Screenshot 2021-07-16 120615](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1eb499cb0ef3f6b2add2483a7cc6bb900d40f81.jpeg)  
 ![Screenshot 2021-07-16 130409](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e65c3b23c0b8614c36523ae147e920f1812efac.jpeg)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [16 July 2021 11:25 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/87 "2021-07-16T11:25:45Z")

</div>

Maybe not enough but….you have /n when it should be \n

Second possible problem could be your user has no access rights to the port

But first try to correct the thing mentioned

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 July 2021 11:28 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/88 "2021-07-16T11:28:24Z")

</div>

and sometime devices prefer `\r` rather than `\n` so try that also.

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [16 July 2021 11:29 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/89 "2021-07-16T11:29:18Z")

</div>

oh, my fault.  
But it Works!!

 ![Screenshot 2021-07-16 132851](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4e565d790f1db0e43d8c6a1e46a9ebf84a045fa.jpeg)

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [16 July 2021 11:29 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/90 "2021-07-16T11:29:48Z")

</div>

thank you ! I keep that in mind when I connect other devices 🙂

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [16 July 2021 11:47 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/91 "2021-07-16T11:47:05Z")

</div>

Good news! Now you can continue to read light values from your device!

---

<div class="post-metadata">

**Author:** ![Beginner96](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Beginner96](https://discourse.nodered.org/u/Beginner96)\
**Post date:** [26 July 2021 09:52 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/92 "2021-07-26T09:52:55Z")

</div>

Thank you very much !  
It works completely fine, here is an example. The value matches with the one on the display of the device. 🙂

![WICHTIG](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6904f106485a4cd3d38471ea40e36cffc6733f9.jpeg)

---

<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:** [24 September 2021 09:53 UTC](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535/93 "2021-09-24T09:53:12Z")

</div>

Closed on 24 September 2021 09:53 UTC

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

[Previous page](https://discourse.nodered.org/t/python-script-into-json-file-for-node-red/45535.md?page=4)
