How to Send a STRING/JSON to a .txt File on another PC

Hi, i'm a bit new to Node-RED and i was asked a question by a customer: Can I set up some way to store (Locally on their PC) a backup log of the JSON Strings that is sent to their DB in case something happens and i had a thought to send a copy of that String to a .txt file but i cannot seem to figure it out.
How it goes is PLC does its jobs, marks a product, Sends out JSON String to DB if it was Good or Bad etc.
Using a CtrlX PLC with Node-RED addon with an IXON Network Switch for remote connection

I use write file node along with a template node in parallel to mysql database update, in case mysql server is shutdown for any reason.

How did you use the Write Node? I routed mine like this: "192.168.120:9200\C:\Users\CustomerPC\Desktop\MarkingResults.txt"
Tried without the IP but i still cannot get it to Write into the .txt file

Is not a valid IPv4 address.

you are absolutely correct, missed the subnet number, my bad, will make the change and test it

1 Like

Don't feel bad...I make that kind of error WAY too often, hence my username. :roll_eyes:

Fair enough haha but i made the IP change, no difference text file still empty, The Inject node contains the same type of info as the PLC would send out:
insert results (art_brand ,serial_nr ,time_marking ,result_laser_marking ,mo_nr,charge ) values ('20239112-0500','Z24210001',GETDATE(),'Ok','000000000','Not Used')

Been thinking if i have to use some kind os Conversion Node to make the Text file happy?

Add a Debug node to the output of the TCP Request node. Configure it like this so you can see what you're sending to the file write node.

image

EDIT: It would also be helpful if you post an image of the file write node properties like I did for the debug node.

Yes sir, give me one sec to set up the debug Node, until then here is an image of the Write Properties

In the Filename, remove everything up to "C:..." to get a valid path/file.

EDIT: Sorry, should have noticed that first.

Well, Idk what happened, had to cut the power real quick as the other machine we got to the same customer needed power real quick, plugged it back in, boot is fine and Node-Red is green... except the PC that is on but it cannot connect through Node-Red now, this is starting to e a interesting friday lol

EDIT: yes i closed down the PC properly before anyone asks haha

Alrighty Update: Everything is back up and running, found that the TCP Port is for a certain software so i cannot use that to Write To a file, Removed that and inserted the Fix LosinIt recommended, still no sucess sadly. The New File Path is as follows:
C:\Users\CustomerPC\Desktop\MarkingResults.txt


NR3

Can you clarify if the file you want to write is on the same PC as Node-red?

Does it work if you setup the write file node with
C:/Users/CustomerPC/Desktop/MarkingResults.txt (ie Unix rather than Dos style slash character)

As i put in the topic header, Node-RED is on a CtrlX-PLC (Bosch PLC) and is run through their Web-server system, the PC is External to that system but still on the same machine, connected to the PLC through EtherCAT bus

EDIT: this is what happens with the solution you wanted me to try
NR4

Sadly I know nothing about CtrlX-PLC, EtherCATs or multiple devices on the same machine.

However, it seems unsurprising that you can't access a user's home folder from another [virtual?] machine without setting up shared folders, NAS, FTP, SSHFS etc.

Well, i still got no sucess on getting this to work. The Node-RED instance is fully virtual unlike the PC i want to thransfer the String to. Been thinking if i'd try to use one of the Link Nodes? could that work theoretically?

The easiest way to get this to work is have the Virtual Machine that is running NR mount the drive of the machine you wish to write to.

Presumably you know how to share out a directory/folder on Windows and make it available ??

  1. Create a new user on the windows PC and assing it a password
  2. Ensure file sharing is turned on and enabled
  3. go to the directory you want to share on windows in File Manager/Explorer and Right click and then choose share this folder - you should be able to select the user you created it will look something like this

image

Then on the NR box create a directory to mount it to - usually by convention in the /mnt folder

so maybe a directory with the name

mkdir /mnt/windows

make sure the user that is running Node Red has permission to read and write to this folder

(chown and chmod)

Then mount the windows shared directory into that folder

The command will look something like this

//windowsIPAddrress/sharedfolder /mnt/windows cifs credentials=/etc/win-credentials,iocharset=utf8,sec=ntlmv2 0 0

That is the command you can put into your FSTab file so this will be available each time the machine is restarted.

Craig

1 Like

the Machine NR is on is a PLC, not an actual Virtual Machine, so i cannot acesss a NR Box or have an User Run NR as it is run automatically when the PLC is booted.
NR5
As i do Appreciate the replies i get, i don't think this can work from my undestanding that it is possible with this instance of Node-RED. It is not a Virtual Machine, they way i acess this is by directly putting in the PLC:s IP and connecting through a web browser, it does nor run off a standard PC.

In that case you could use MQTT. Install node red and mosquitto on the PC, connect to mosquitto from the PLC using the MQTT nodes, and pass the required data across. Then in node-red in the PC pick up the data and write the files.

If you don't know about MQTT then see this tutorial MQTT Essentials - All Core Concepts Explained