dabamos / openadms-node

Automatic deformation monitoring system for geodetical and geotechnical control measurements in the Internet of Things.
https://www.dabamos.de/
BSD 2-Clause "Simplified" License
11 stars 4 forks source link

mqtt - Unexpected disconnection from 192.168.31.144:5432 #4

Closed geovey closed 4 years ago

geovey commented 4 years ago

I have configured PostgreSQL, but openadms node always fails to upload IP address data in LAN;

2020-08-28T14:24:25 - ERROR - mqtt - Unexpected disconnection from 192.168.31.144:5432 2020-08-28T14:24:25 - INFO - mqtt - Reconnecting to 192.168.31.144:5432 ... 2020-08-28T14:24:27 - INFO - job - Starting job "getValues" for port "com1" ... 2020-08-28T14:24:27 - ERROR - mqtt - Publishing message failed: no connection

interkosmos commented 4 years ago

Are you using the Git master branch or the old 0.7 release of OpenADMS? Have you enabled the internal MQTT broker or have you started an external one?

geovey commented 4 years ago

I use version 0.8 and run the following command: pipenv run ./openadms.py --config ./config/gnss.json --with-mqtt-broker --debug

In addition, the user cannot verify the login by setting the scratch-sha-256 in the PostgreSQL on the OpenADMS server.

gnss.json The contents of the document are as follows:

{
    "core": {
        "modules": {
            "com1": "modules.port.SerialPort",
            "schedulerUsb": "modules.schedule.Scheduler",
            "preProcessor": "modules.processing.PreProcessor",
            "fileExporter": "modules.export.FileExporter"
        },
        "project": {
            "name": "GNSS Project",
            "id": "afb9ae8ee1f411eab6ae00265e5d7c70",
            "description": "Project for testing the GNSS."
        },
        "node":{
            "name": "GNSS Sensor Node 1",
            "id": "044ba088e1f511eab6ae00265e5d7c70",
            "description": "The only sensor node in this project."
        },
        "intercom": {
            "mqtt": {
                "host": "192.168.31.144",
                "port": 5432,
                "keepAlive": 60,
                "topic": "openadms",
                "tls": false
            }
        }
    },
    "sensors": {
        "gnss": {
            "description": "Mosaic-X5",
            "type": "GNSS",
            "observations": [
            {
                "name": "getValues",
                "description": "gets gnss nmea-gga",
                "enabled": true,
                "nextReceiver": 0,
                "onetime": false,
                "target": "gnss",
                "type": "observation",
                "receivers": [
                    "preProcessor",
                    "fileExporter"
                ],
                "requestsOrder": [
                  "draft"
                ],
                "requestSets": {
                    "draft": {
                        "enabled": true,
                        "request": "",
                        "response": "",
                        "responseDelimiter": "\r",
                        "responPattern": "(?P<gga>\\*)",
                        "sleepTime": 1.0,
                        "timeout": 1.0
                    }
                },
                "responseSets": {
                    "gga": {
                        "type": "string",
                        "unit": "none"
                    }
                },
                "sleepTime": 1.0
            }
            ]
        }
    },
    "modules": {
        "ports": {
            "serial": {
                "com1": {
                    "port": "/dev/ttyACM1",
                    "baudRate": 115200,
                    "byteSize": 8,
                    "stopBits": 1,
                    "parity": "none",
                    "timeout": 2.0,
                    "softwareFlowControl": false,
                    "hardwareFlowControl": false,
                    "maxAttempts": 1
                }
            }
        },
        "schedulers": {
            "schedulerUsb": {
                "port": "com1",
                "sensor": "gnss",
                "schedules": [
                {
                    "enabled": true,
                    "startDate": "2020-08-18",
                    "endDate": "2020-12-21",
                    "weekdays": {},
                    "observations": [
                      "getValues"
                    ]
                }
                ]
            }
        },
        "fileExporter": {
            "fileExtension": ".txt",
            "fileName": "{{port}}_{{date}}",
            "fileRotation": "monthly",
            "paths": [
              "./data"
            ],
            "separator": "\r",
            "dateTimeFormat": "YYY-MM-DDTHH:mm:ss.SSSSS",
            "saveObservationId": true
        }
    }
}
interkosmos commented 4 years ago

If you are using the internal MQTT broker, you must set the MQTT host address to 127.0.0.1, as the broker won’t listen to your external IP (192.168.31.144).

geovey commented 4 years ago

192.168.31.144, which is the IP address of my intranet server;

My openadms server is not deployed locally.

interkosmos commented 4 years ago

If you want to use the internal MQTT broker, you have to set the host address to localhost:

        "intercom": {
            "mqtt": {
                "host": "127.0.0.1",
                "port": 5432,
                "keepAlive": 60,
                "topic": "openadms",
                "tls": false
            }
        }

Or, run an MQTT broker on your intranet server instead.

geovey commented 4 years ago

According to your settings, the following error occurs:

2020-08-28T17:51:34 - VERBOSE - preProcessor - Connecting module "preProcessor" to 127.0.0.1:5432 ... 2020-08-28T17:51:34 - DEBUG - preProcessor - Starting worker "preProcessor" ... 2020-08-28T17:51:34 - DEBUG - moduleManager - Starting module "fileExporter" ... 2020-08-28T17:51:34 - VERBOSE - fileExporter - Connecting module "fileExporter" to 127.0.0.1:5432 ... 2020-08-28T17:51:34 - DEBUG - fileExporter - Starting worker "fileExporter" ... 2020-08-28T17:51:39 - INFO - job - Starting job "getValues" for port "com1" ... 2020-08-28T17:51:39 - ERROR - mqtt - Publishing message failed: no connection 2020-08-28T17:51:39 - SPAM - schedulerUsb - Published message with QoS 0 to "openadms/com1" 2020-08-28T17:51:39 - DEBUG - job - Next observation starts in 1.0 s

interkosmos commented 4 years ago

Are you running OpenADMS Node definitely with --with-mqtt-broker? Does the example configuration examples/virtual.json work?

geovey commented 4 years ago

Yes, I added '--with-mqtt-broker' to the run command; In addition,the example configuration examples/virtual.json word very well.

I think that if I transfer and store data to postgresql via MQTT protocol, I should fill in the IP address (192.168.31.144) and port (5432) of the server database instead of the local ip (127.0.0.1) and port (1883); However, I have been unable to successfully connect to the postgresql database, what should I do?

interkosmos commented 4 years ago

MQTT is used for message passing between OpenADMS Node modules. You cannot send MQTT messages directly to the database server. Make sure that the port in the MQTT configuration matches the MQTT broker settings (i. e., port 1883). Port 5432 is probably the PostgreSQL port. If you want to export observation data to an OpenADMS Server instance, use the CloudExporter module. See config/examples/cloud.json for an example.

geovey commented 4 years ago

Thank you very much for your patient answers. I understand what you mean, but there are still errors in my operation;

2020-08-31T14:53:19 - ERROR - preProcessor - Invalid regular expression for response "draft" in observation "getValues" of target "gnss" from sensor "gnss" on port "com1"

I think it is likely that respondPattern is filled in incorrectly. How can I modify it for different sensors?

"requestSets": { "draft": { "enabled": true, "request": "", "response": "", "responseDelimiter": "\r", "responPattern": "(?P\*)", "sleepTime": 1.0, "timeout": 1.0 } },

geovey commented 4 years ago

For example, to read the NMEA data of a GNSS receiver, how should I fill in respondPattern? 2020-08-31T15:04:02 - VERBOSE - com1 - Sending request "draft" of observation "getValues" to sensor "gnss" ... 2020-08-31T15:04:02 - VERBOSE - com1 - Received response "*$GPGGA,070402.00,3028.8924597,N,11424.7822492,E,1,16,1.9,39.5623,M,-13.5785,M,,7D\r**" for request "draft" of observation "getValues" from sensor "gnss" 2020-08-31T15:04:02 - INFO - job - Starting job "getValues" for port "com1" ... 2020-08-31T15:04:02 - SPAM - schedulerUsb - Published message with QoS 0 to "openadms/com1" 2020-08-31T15:04:02 - DEBUG - job - Next observation starts in 1.0 s 2020-08-31T15:04:03 - SPAM - com1 - Published message with QoS 0 to "openadms/preProcessor" 2020-08-31T15:04:03 - SPAM - com1 - Received message of type "observation" from "job" 2020-08-31T15:04:03 - VERBOSE - com1 - Sending request "draft" of observation "getValues" to sensor "gnss" ... 2020-08-31T15:04:03 - SPAM - preProcessor - Received message of type "observation" from "com1" 2020-08-31T15:04:03 - ERROR - preProcessor - Invalid regular expression for response "draft" in observation "getValues" of target "gnss" from sensor "gnss" on port "com1"

geovey commented 4 years ago

2020-08-31T18:14:08 - ERROR - preProcessor - Response "$GPGGA,101409.00,3028.8928681,N,11424.7898123,E,1,16,1.7,28.4207,M,-13.5779,M,,*79\r\n" of request "draft" in observation "getValues" of target "gnss" from sensor "gnss" on port "com1" does not match extraction pattern

interkosmos commented 4 years ago

The regular expression in the responsePattern field is invalid. Try the pattern (?P<gga>\$.*) instead. Also, make sure the responseDelimiter matches:

"requestSets": {
    "draft": {
        "enabled": true,
        "request": "",
        "response": "",
        "responseDelimiter": "\r\n",
        "responsePattern": "(?P<gga>\$.*)",
        "sleepTime": 1.0,
        "timeout": 1.0
    }
},
"responseSets": {
    "gga": {
        "type": "string",
        "unit": "none"
    }
}

You can test the regular expression on regex101.com.

geovey commented 4 years ago

Thank you very much for your answers, I have successfully read NMEA-GGA. In the next step, I will store the data in the postgresql database, I wish I can complete it smoothly.