Simulation application of a machine and node red

how can I connect a simulation application of a machine to node red?
This applicatin send an http request that contain a JSON file.
The Client http open and close connection for every information sended to server.
Every event have a specific JSON that it will be send.

What part do you want Node-RED to play?

Node Red should receive the data (in json format) and produce a response in json format. Application calls post and get which must be intercepted by node red to produce a response depending on the call

See the section HTTP Endpoints in the node red cookbook https://cookbook.nodered.org/

I saw, but i don't know how configurate the flow. I attach the request, containing the json file, made by the simulation program. :

 Inviato
POST /pentamac/messages/Macchina/xm1000/topic/xm1000/stato HTTP/1.1
Host: 127.0.0.1
Referer: http://127.0.0.1/pentamac/messages/Macchina/xm1000/topic/xm1000/stato
content-type: application/json; charset=UTF-8
content-Length: 137

{"data":{"anno":2022,"mese":7,"giorno":14,"ora":12,"minuti":1,"secondi":20},"jobid":0,"evento":{"tipo":1,"valore":0.000000,"stringa":""}}
Ricevuto
Json non formattato correttamente
HTTP/1.1 404 Not Found
Access-Control-Allow-Origin: *
X-Powered-By: Express
Content-Security-Policy: default-src 'none'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 192
Date: Thu, 14 Jul 2022 10:01:20 GMT
Connection: keep-alive
Keep-Alive: timeout=5


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /pentamac/messages/Macchina/xm1000/topic/xm1000/stato</pre>
</body>
</html>

Please don't post screenshots, copy/paste the text. Use the </> button when pasting it in.

Did you try the example flow from the cookbook so you could understand how it works? Once you understand that then what aspect don't you know how to do?

I've tryed with this flow :

[
    {
        "id": "f3ba324142609717",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6869960702da53ad",
        "type": "http in",
        "z": "f3ba324142609717",
        "name": "",
        "url": "/pentamac/messages/Macchina/xm1000/topic/xm1000/stato",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 290,
        "y": 80,
        "wires": [
            [
                "b11df365cb02a3e7"
            ]
        ]
    },
    {
        "id": "b11df365cb02a3e7",
        "type": "template",
        "z": "f3ba324142609717",
        "name": "page",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{ \"Hello\": \"World\" }",
        "x": 410,
        "y": 180,
        "wires": [
            [
                "70dd4eb4709e461d"
            ]
        ]
    },
    {
        "id": "70dd4eb4709e461d",
        "type": "change",
        "z": "f3ba324142609717",
        "name": "Set Headers",
        "rules": [
            {
                "t": "set",
                "p": "headers",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "headers.content-type",
                "pt": "msg",
                "to": "application/json",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 570,
        "y": 180,
        "wires": [
            [
                "77487f3e1c35fed8",
                "40ac4f05bae5a525"
            ]
        ]
    },
    {
        "id": "77487f3e1c35fed8",
        "type": "http response",
        "z": "f3ba324142609717",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 730,
        "y": 180,
        "wires": []
    },
    {
        "id": "40ac4f05bae5a525",
        "type": "debug",
        "z": "f3ba324142609717",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 870,
        "y": 100,
        "wires": []
    }
]

Is the client using an html POST? If so then you need to configure the http node as POST. One of the example is for json post.

Ok, yes thanks. Now, it send json data and i'll receive it in Node Red.
One advice, on the json response, which must be defined by the structure attached below, how can I insert the right "timestamp" and any errors?

{"_timestamp":"2017-07-03 08:34:17","_success":"Message sent to topic xm1000-
600-37005 as stato","_error":""}

Actually, the flow is this:

[
    {
        "id": "f3ba324142609717",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6869960702da53ad",
        "type": "http in",
        "z": "f3ba324142609717",
        "name": "",
        "url": "/pentamac/messages/Macchina/xm1000/topic/xm1000/stato",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 250,
        "y": 80,
        "wires": [
            [
                "ff3a15d3d1c43102",
                "b11df365cb02a3e7",
                "6c44ce68e6421e30"
            ]
        ]
    },
    {
        "id": "b11df365cb02a3e7",
        "type": "template",
        "z": "f3ba324142609717",
        "name": "page",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\"_timestamp\":\"2017-07-03 08:34:17\",\"_success\":\"Message sent to topic xm1000-\n600-37005 as stato\",\"_error\":\"\"}",
        "x": 410,
        "y": 180,
        "wires": [
            [
                "70dd4eb4709e461d"
            ]
        ]
    },
    {
        "id": "70dd4eb4709e461d",
        "type": "change",
        "z": "f3ba324142609717",
        "name": "Set Headers",
        "rules": [
            {
                "t": "set",
                "p": "headers",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "headers.content-type",
                "pt": "msg",
                "to": "application/json",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 590,
        "y": 180,
        "wires": [
            [
                "77487f3e1c35fed8",
                "40ac4f05bae5a525"
            ]
        ]
    },
    {
        "id": "77487f3e1c35fed8",
        "type": "http response",
        "z": "f3ba324142609717",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 790,
        "y": 180,
        "wires": []
    },
    {
        "id": "40ac4f05bae5a525",
        "type": "debug",
        "z": "f3ba324142609717",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 120,
        "wires": []
    },
    {
        "id": "ff3a15d3d1c43102",
        "type": "debug",
        "z": "f3ba324142609717",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 80,
        "wires": []
    },
    {
        "id": "6433fccad151ee5d",
        "type": "http in",
        "z": "f3ba324142609717",
        "name": "",
        "url": "/pentamac/messages/timeout/XM1000",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 210,
        "y": 320,
        "wires": [
            [
                "f5d45542a2d085f3",
                "6c44ce68e6421e30"
            ]
        ]
    },
    {
        "id": "f5d45542a2d085f3",
        "type": "debug",
        "z": "f3ba324142609717",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 400,
        "wires": []
    },
    {
        "id": "6c44ce68e6421e30",
        "type": "join",
        "z": "f3ba324142609717",
        "name": "",
        "mode": "auto",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": "false",
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "x": 210,
        "y": 200,
        "wires": [
            [
                "b11df365cb02a3e7"
            ]
        ]
    }
]

So, the variables "timestamp" is fixed and always the same.

What is the Join node in the flow for?

In the template node you can insert data from a message into the result. Look at the help text for the node.

you are right, the join node is an error.
And yes, i found that. Thanks.
Last question, is it possible to know what is the time that node red takes to connect to the program, the time it takes to receive and send data? To put this data into the response json

What do mean by the time it takes to connect to the program? How can you put the time it takes to send the data into the response, as by the time you know how long it took you have already sent it? For how long it takes in node red I think there is a node that will time how long messages take in a flow, but I can't immediately find that. Search in the node red flows site and if you can't find it then I suggest asking again in a new thread.

Sorry, bad traslate. I mean the time to wait when connecting before declare timeout; the waiting time when sending before declaring timeout; but now I know these are variables defined before connecting.

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