Node Red TCP connection gives error (index a nil value) on MG400 Dobot

I have a dobot Mg400 with the following code:

And then a simple flow in node red to inject strings using TCP connection (MG400 is the server):

The code is executed as I would expect, robot does commands and I get the reply back (ex. "ScannerIsEmpty!!"), but then dobot studio throws this error:


src0.lua:18: attempt to index a nil value (global 'tcp1')

So why do you post it on the Node Red forum and not in Dobot forum? Because it does not do it when i inject from an app on my phone or the debugging tool in dobot studio, only when done from Node Red. It also does not do it, if i use the TCP out node... but then i wont get a reply and i need that. So what does the TCP request node in Node red do differently to provoke this error?

[
    {
        "id": "c4396e2906bd2811",
        "type": "tab",
        "label": "Server",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fa6a975f06c0d443",
        "type": "inject",
        "z": "c4396e2906bd2811",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "GetFoto",
        "payloadType": "str",
        "x": 120,
        "y": 200,
        "wires": [
            [
                "3710ca17baf02557"
            ]
        ]
    },
    {
        "id": "dddbf63d43621b34",
        "type": "inject",
        "z": "c4396e2906bd2811",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "EmSc",
        "payloadType": "str",
        "x": 110,
        "y": 280,
        "wires": [
            [
                "3710ca17baf02557"
            ]
        ]
    },
    {
        "id": "3710ca17baf02557",
        "type": "tcp request",
        "z": "c4396e2906bd2811",
        "name": "",
        "server": "192.168.1.6",
        "port": "6601",
        "out": "time",
        "ret": "string",
        "splitc": "0",
        "newline": "",
        "trim": false,
        "tls": "",
        "x": 400,
        "y": 280,
        "wires": [
            [
                "602439f8493fcfd9"
            ]
        ]
    },
    {
        "id": "602439f8493fcfd9",
        "type": "debug",
        "z": "c4396e2906bd2811",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 280,
        "wires": []
    }
]

Just tried with python on my node red pc, that yielded the same error as the node red. Is this some ip config that I have wrong on my pc? Will try to swap pc tomorrow (need to set it up).

So it's not hardware specific, but software. Tried another pc: Node red, same error, random tcp client program no problem (same as tcp app on my phone). Somehow the format of the message is different.

Tried adding \n to the string, did not help.

Is it because it gets passed as an object and not a clean String?

Any ideas?

you could use wireshark or tcpdump to capture the traffic for node-red vs your working python script and compare them so see what is different.

Does the dobot software not have a well known protocol like MQTT or HTTP or something? That would be far easier and far more reliable than rolling your own. For example, your raw TCP scratch routine doesn't check for any start markers or end markers or use any kind of CRC for error checking so will be flakey and susceptible to buffered coms etc.

I figured it out. It was because Python and Node Red pr. default closes down the TCP connection after end message, which my TCP clients on my phone and computer did not. So its Dobots way of saying "I lost connection", which in my opinion is not the most user-friendly way... but I am by no way a coder by profession, so maybe this was obvious to a more experienced coder.

Fix:

Hi Steve

Thanks for your replies. No unfortunatly it only commes with TCP or Modbus. It has its small quirks, but for the price i am quit impressed. Its silent, precise and fast and it costs around 2k $

I am making an application for taking old polaroid fotos in and out of a scanner, so i do not have to stand and wait for 2min pr. scan:

1 Like

That looks cool.

Modbus might be a good bet (there are modbus nodes)

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