# Insert data from udp

**URL:** <https://discourse.nodered.org/t/insert-data-from-udp/85627>\
**Category:** General\
**Tags:** function-node\
**Created:** [17 February 2024 22:41 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627 "2024-02-17T22:41:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)\
**Post date:** [17 February 2024 22:41 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/1 "2024-02-17T22:41:36Z")

</div>

HI

I have this data coming from a MQTT connect to my weather station:

```auto
dataGMTTime=2023/07/05 03:38:46
cwinfo=Serial: 2387, FW: 5.88
clouds=34.350000
temp=34.310000
wind=-1
gust=-1
rain=2450
lightmpsas=23.57
switch=0
safe=0
hum=45
dewp=20.680000
rawir=46.190000
abspress=1014.687500
relpress=1015.816851

```

I create a Windows MYSQL database table:

```auto
SELECT `timestamps`.`create_time`,
    `timestamps`.`clouds`,
    `timestamps`.`temp`,
    `timestamps`.`wind`,
    `timestamps`.`gust`,
    `timestamps`.`rain`,
    `timestamps`.`lightmpsas`,
    `timestamps`.`dew`,
    `timestamps`.`rawir`,
    `timestamps`.`abspress`,
    `timestamps`.`relpress`
FROM `obs`.`timestamps`;
SELECT * FROM obs.timestamps;

```

Here are the nodes, HTTP get from the weather station, the function that I get from Lunatico connected to a Switch node to the gauge etc.

```auto
[
    {
        "id": "274d0c55f0ce31c2",
        "type": "inject",
        "z": "347a75cd5d16739c",
        "name": "5 secs",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "30",
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 130,
        "y": 120,
        "wires": [
            [
                "3c89cda003e1ada5"
            ]
        ]
    },
    {
        "id": "3c89cda003e1ada5",
        "type": "http request",
        "z": "347a75cd5d16739c",
        "name": "Solo last data",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://1xxxxxxxxx/cgi-bin/cgiLastData",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "basic",
        "senderr": false,
        "headers": [],
        "x": 200,
        "y": 180,
        "wires": [
            [
                "a618203e92f9ec15",
                "14ae07e98da30ed0"
            ]
        ]
    },
    {
        "id": "14ae07e98da30ed0",
        "type": "function",
        "z": "347a75cd5d16739c",
        "name": "process-data",
        "func": "\nlet payload = msg.payload;\n\nlet data_out = {}\n\nif (payload == \" \")\n\n return;\n\n//node.log(\"payload=\" +typeof payload +\" \"+payload);\n\nlet data = payload.split(\"\\n\");\n\nnode.log(\"data =\" + data);\n\nif (typeof data == \"undefined\" || data == \"\")\n\n node.log(\"empty\");\n\nfor (let i = 0; i < data.length; i++) {\n\n\n\n let line = data[i].split(\"=\");\n\n msg.topic = line[0];\n\n if (line[0] == \"clouds\" || line[0] == \"dewp\" || line[0] == \"rawir\")\n\n line[1] = parseFloat(line[1]).toFixed(2);\n\n if (line[0] == \"abspress\" || line[0] == \"relpress\" || line[0] == \"lightmpsas\")\n\n line[1] = parseFloat(line[1]).toFixed(2);\n\n if (line[0] == \"temp\") {\n\n line[1] = parseFloat(line[1]) * 9 / 5 + 32;\n\n line[1] = line[1].toFixed(2);\n\n }\n\n msg.payload = line[1]\n\n data_out[line[0]] = line[1]; //make object\n\n if (typeof msg.topic != \"undefined\" || msg.topic != \"\") {\n\n node.send(msg);\n\n node.log(\"sent \" + msg.topic);\n\n }\n\n\n\n}\n\nnode.log(\"out_data = \" + JSON.stringify(data_out));\n\nlet temp_time = data_out[\"dataGMTTime\"];\n\nlet d = new Date(temp_time);\n\nlet timestamp = d.getTime();\n\nnode.log(\"timestamp=\" + timestamp);\n\nlet clouds = data_out[\"clouds\"];\n\nlet temp = data_out[\"temp\"];\n\nlet wind = data_out[\"wind\"];\n\nlet gust = data_out[\"gust\"];\n\nlet rain = data_out[\"rain\"];\n\nlet lightmpsas = data_out[\"lightmpsas\"];\n\nlet hum = data_out[\"hum\"];\n\nlet dewp = data_out[\"dewp\"];\n\nlet rawir = data_out[\"rawir\"];\n\nlet abspress = data_out[\"abspress\"];\n\nlet relpress = data_out[\"relpress\"];\n\nmsg.params = { $timestamp: timestamp, $clouds: clouds, $temp: temp, $wind: wind, $gust: gust, $rain: rain, $lightmpsas: lightmpsas, $hum: hum, $dewp: dewp, $rawir: rawir, $abspress: abspress, $relpress: relpress };\n\nmsg.topic = \"database\";\n\nnode.send(msg);",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 180,
        "wires": [
            [
                "d6c48eb9cf006939"
            ]
        ]
    },
    {
        "id": "a618203e92f9ec15",
        "type": "mqtt out",
        "z": "347a75cd5d16739c",
        "name": "MQTT",
        "topic": " something",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "b231b989b9dfe837",
        "x": 365,
        "y": 120,
        "wires": [],
        "l": false
    },
    {
        "id": "d9e5318a8e660990",
        "type": "mqtt in",
        "z": "347a75cd5d16739c",
        "name": "",
        "topic": "something",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "c1d150f1e0ea035e",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 190,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "b231b989b9dfe837",
        "type": "mqtt-broker",
        "name": "",
        "broker": "mosquitto.org",
        "port": "xxxx",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "c1d150f1e0ea035e",
        "type": "mqtt-broker",
        "name": "",
        "broker": "mosquitto.org",
        "port": "xxxx",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

```

I am struggling to find the way to insert this data, any help to guide me me will be appreciate  
[Moderator edit to format code, use pencil icon yo see the edit]

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 February 2024 23:47 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/2 "2024-02-17T23:47:58Z")

</div>

When you post either code or data in this forum, it makes life much easier for the people giving their time to help you if you follow this simple procedure:

Copy data using the little button in the debug output:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b7aa063e71fbc4f175f6b2d5c432e36d3658a6b.png)  
Or export your flow and copy to clipboard.

In this forum click on the `</>` button  
Paste your data or code over the top of the highlighted "type or paste code here"  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/56f032da1fc7ba67aebd00a11362951e61854387.png)

This will ensure that your flow can be exported, unlike what you have posted above, and the data is available for us to view and experiment with.

---

<div class="post-metadata">

**Author:** ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)\
**Post date:** [17 February 2024 23:57 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/3 "2024-02-17T23:57:42Z")

</div>

[flows(1).json](https://discourse.nodered.org/uploads/short-url/yApnUU975RrZMEYm6XB9mwqGkbp.json) (7.6 KB)

Please forgive me, I try but didn't understand the symbol \</\>, let me know is this is the right way.  
[Moderator edit, attachments do not require code formating]

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [18 February 2024 00:41 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/4 "2024-02-18T00:41:09Z")

</div>

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

Sometimes that button is hidden and you have to click the last button on the right, the gear wheel, to see it.

---

<div class="post-metadata">

**Author:** ![telescopio](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@telescopio](https://discourse.nodered.org/u/telescopio)\
**Post date:** [18 February 2024 00:51 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/5 "2024-02-18T00:51:13Z")

</div>

The last one I did it,Is that the correct way to do it? or I still missing something

---

<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:** [18 May 2024 00:51 UTC](https://discourse.nodered.org/t/insert-data-from-udp/85627/6 "2024-05-18T00:51:18Z")

</div>

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