aisstream / issues

7 stars 3 forks source link

[Support/Feature Request]Node-Red #48

Open cscompton opened 10 months ago

cscompton commented 10 months ago

Anyone have an example of a working node-red flow? I have the inject setup with the bounding box and api key, never get a response through the websocket listen on connection.

Parabellum123 commented 9 months ago

I have an error: "Subscription Object Is Malformed" , did you have the same as me ?

cscompton commented 9 months ago

I have an error: "Subscription Object Is Malformed" , did you have the same as me ?

I just don't get a response. Happy to share a flow.

Parabellum123 commented 9 months ago

Did you have other Free API for AIS ?

vpsmedeiros commented 8 months ago

I had the same non responsive/bad api key/malformed message issues until I found a proper way to send the subscription message. Here's a working flow I have setup.

In the 'connection message' function box insert your API key on the first line where it says "your api key" following the //comment example below it.

If you see the connection icon below the websocket node stay green after 3 seconds, then you know the subscription message was received from AIS Stream. The stream of messages should start coming in quick from 2nd websocket node. Try waiting like 10 seconds if you don't get anything immediately. If the connection icon goes back to red/disconnected, Try injecting the code again. If you don't press the inject flow button within the 3 second connection window, nothing will send.

The 'aisoff' code injection works by sending a bad API key in the subscription message which makes the subscription close. If anyone has a better idea of doing this I'd like to know.

[
    {
        "id": "d47c3bfd34430d83",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "efa50e14fef4c9aa",
        "type": "debug",
        "z": "d47c3bfd34430d83",
        "name": "Payload in JSON",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 260,
        "wires": []
    },
    {
        "id": "9fe842bd6061e638",
        "type": "websocket out",
        "z": "d47c3bfd34430d83",
        "name": "",
        "server": "",
        "client": "48ac6132592d5218",
        "x": 720,
        "y": 100,
        "wires": []
    },
    {
        "id": "f043767eabfa7aa0",
        "type": "websocket in",
        "z": "d47c3bfd34430d83",
        "name": "",
        "server": "",
        "client": "48ac6132592d5218",
        "x": 220,
        "y": 260,
        "wires": [
            [
                "ff501c9ed0b9bfae"
            ]
        ]
    },
    {
        "id": "75fd1b1dd5b44113",
        "type": "function",
        "z": "d47c3bfd34430d83",
        "name": "subscription msg",
        "func": "let apikey = \"your api key\";  // use quotations in the api key variable like the example below.\n//let apikey = \"123456xxxxxx\";\n\nif (msg.payload == \"aison\") {\n    msg.payload = {\n        Apikey: apikey,\n        BoundingBoxes: [[[38.7011941, -124.579914], [36.2216758, -120.492962]]],\n        //FiltersShipMMSI: [\"368207620\", \"367719770\", \"211476060\"], // Optional!\n        FilterMessageTypes: [\"ShipStaticData\", \"StandardClassBPositionReport\"] // Optional! ShipStaticData\n    }\n}\nif (msg.payload == \"aisoff\") {\n    msg.payload = {\n        Apikey: \"reset\",\n        BoundingBoxes: [[[38.7011941, -124.579914], [36.2216758, -120.492962]]],\n        //FiltersShipMMSI: [\"368207620\", \"367719770\", \"211476060\"],\n        FilterMessageTypes: [\"ShipStaticData\", \"StandardClassBPositionReport\"]\n    }\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 120,
        "wires": [
            [
                "9fe842bd6061e638",
                "c398dbdc33cc509b"
            ]
        ]
    },
    {
        "id": "ff501c9ed0b9bfae",
        "type": "json",
        "z": "d47c3bfd34430d83",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 490,
        "y": 260,
        "wires": [
            [
                "efa50e14fef4c9aa"
            ]
        ]
    },
    {
        "id": "bf7d750b5368bff2",
        "type": "inject",
        "z": "d47c3bfd34430d83",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "aison",
        "payloadType": "str",
        "x": 130,
        "y": 80,
        "wires": [
            [
                "75fd1b1dd5b44113"
            ]
        ]
    },
    {
        "id": "c398dbdc33cc509b",
        "type": "debug",
        "z": "d47c3bfd34430d83",
        "name": "Subscription message.",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 160,
        "wires": []
    },
    {
        "id": "30ae79d0cd078dd9",
        "type": "inject",
        "z": "d47c3bfd34430d83",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "aisoff",
        "payloadType": "str",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "75fd1b1dd5b44113"
            ]
        ]
    },
    {
        "id": "48ac6132592d5218",
        "type": "websocket-client",
        "path": "wss://stream.aisstream.io/v0/stream",
        "tls": "",
        "wholemsg": "false",
        "hb": "0",
        "subprotocol": ""
    }
]