UK power consumption to Twitter

Get real-time UK power consumption from http://realtimeweb-prod.nationalgrid.com/SystemData.aspx then Tweet with some description.

[
    {
        "id": "5d138f6c.a2ec7",
        "type": "inject",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "300",
        "crontab": "",
        "once": false,
        "x": 743,
        "y": 152,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "496fa39e.b6905c"
            ]
        ]
    },
    {
        "id": "496fa39e.b6905c",
        "type": "http request",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "url": "http://realtimeweb-prod.nationalgrid.com/SystemData.aspx",
        "x": 910,
        "y": 205,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "14d4cb5.feb2b35"
            ]
        ]
    },
    {
        "id": "14d4cb5.feb2b35",
        "type": "function",
        "name": "UK electricity",
        "func": "if (~msg.payload.indexOf('<span')) {\n  var words = msg.payload.split(\"<p\")[1].split(\"ContentPlaceHolder1\");\n  if (words.length >= 3) {\n    msg.payload = {};\n    msg.payload.demand = parseInt(words[1].split(\">\")[1]);\n    msg.payload.frequency = parseFloat(words[3].split(\">\")[1]);\n    msg.payload.time = words[2].split(\">\")[1];\n\n    // Create the true/false signal based on the frequency.\n    frq50 = {};\n    frq50.payload = (msg.payload.frequency >= 50) ? true : false;\n\n\tvar toTweet = {};\n\ttoTweet.payload = \"UK power consumption \" + msg.payload.demand +\"MW\" \n\t\t\t\t\t\t+ \" at \" + msg.payload.time.split(\"<\")[0] + \"\\n\"+\n\t\t\t\t\t\t\" (Tweet from Node-RED on Raspberry Pi)\";\n\t\n    return [msg,frq50,toTweet];\n  }\n}",
        "outputs": "3",
        "x": 1070,
        "y": 112,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "b14aa289.4eb56"
            ],
            [
                "6a27e576.95d81c"
            ],
            [
                "3c9c78bb.c36388"
            ]
        ]
    },
    {
        "id": "b14aa289.4eb56",
        "type": "debug",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 1247,
        "y": 45,
        "z": "c3aed0d3.3ce58",
        "wires": []
    },
    {
        "id": "6a27e576.95d81c",
        "type": "debug",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 1259,
        "y": 99,
        "z": "c3aed0d3.3ce58",
        "wires": []
    },
    {
        "id": "3c9c78bb.c36388",
        "type": "twitter out",
        "twitter": "",
        "name": "Tweet",
        "x": 1255,
        "y": 179,
        "z": "c3aed0d3.3ce58",
        "wires": []
    }
]
s0013254

Flow Info

created 2 years, 1 month ago

Node Types

Core
  • debug (x2)
  • function (x1)
  • http request (x1)
  • inject (x1)
  • twitter out (x1)

Tags

  • Twitter
  • HTTP
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option