Insert data from udp

HI

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

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:

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.

[
    {
        "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 ]

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
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

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.

flows(1).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 ]

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

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

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