GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

Node-red with docker on raspberry Pi #44

Closed jemamena closed 4 years ago

jemamena commented 4 years ago

I have installed Node-Red with docker in a RPI and I'm trying to connect to GCP, so far unsuccessfully.

I get this error in the debug messages:

Error: Unable to detect a Project Id in the current environment. To learn more about authentication and Google APIs, visit: https://cloud.google.com/docs/authentication/getting-started

It seems like it has to do with the environment variable GOOGLE_CLOUD_PROJECT. Reading the installation steps, I get stuck in this part as it is not started through the systemctl daemon:

"...Note: For Raspberry Pi users - There is the option of starting Node-RED automatically through the Linux systemctl daemon. This system does not use global environment variables and thus you must explicitly define the variable to use.

Edit the file /lib/systemd/system/nodered.service

and add a line which reads:

Environment="GOOGLE_CLOUD_PROJECT=" ..."

I have added the JSON key message in the credentials but it doesn't seem to do the trick yet.

Help would be much appreciated. Thanks

kolban-google commented 4 years ago

Howdy and thanks for raising an issue. If you were running Node-RED natively in a Raspberry PI then the part about editing the nodered.service would apply. However, I believe I am hearing that you are running in a Docker container where docker itself is running on the RPI. Is this a Docker image you yourself have built or is it a public image ... and if so, which one? I will attempt to test with the same container.

Can you post back with the exact command/recipe you are using to start the container?

jemamena commented 4 years ago

Hello,

I have followed Andreas Spiess video about docker with RPI. https://www.youtube.com/watch?v=a6mjt8tWUws

this is the docker compose for node-red:

nodered: container_name: nodered build: ./services/nodered/. restart: unless-stopped user: "0" env_file: ./services/nodered/nodered.env ports:

kolban-google commented 4 years ago

Howdy ... great ... thank you for this. I have been out of town all this week and am travelling home today. It is at home where my Raspberry PI instances live. I'll be spinning up an RPI tomorrow at the latest and will report back. Again, thank you for the info/links ... this will allow me to attempt to recreate the same procedure as yourself.

kolban-google commented 4 years ago

Sat down ready to do work and couldn't find my micro HDMI cable adapter for the RPI 4 I have. Have ordered two new ones from Amazon and am now awaiting for their delivery before I can test further.

kolban-google commented 4 years ago

I got my HDMI cables and worked towards a recreate. This is the recipe I followed on a new Pi:

sudo bash
curl -sSL https://get.docker.com | sh
usermod -aG docker pi
reboot

docker run -p 1880:1880 nodered/node-red

open a chrome browser to rpi:1880.
Install the package node-red-contrib-google-cloud.
Ran the sentiment example after generating and defining a security key.

and .... it all worked. No issues. What I'd like you to try is the recipe described here and see how you get on.

Here is the flow I tested with ... you will have to add your own keys. Is there a flow you can share which is failing if this works?

[
    {
        "id": "affb634f.32158",
        "type": "tab",
        "label": "Sentiment",
        "disabled": false,
        "info": "This example allows you to submit both positive\nand negative sentiment into the sentiment\nprocessing.  The results are logged to the debug panel.\n\nClicking on the Positive inject starts a flow with\na positive sentiment text message while clicking\non the Negative inject starts a flow with a negative sentiment."
    },
    {
        "id": "850354bc.da5018",
        "type": "google-cloud-language-sentiment",
        "z": "affb634f.32158",
        "account": "",
        "keyFilename": "",
        "languageCode": "en",
        "name": "",
        "x": 360,
        "y": 100,
        "wires": [
            [
                "dd41b34.c87235"
            ]
        ],
        "info": "Process sentiment analysis on the incoming text."
    },
    {
        "id": "2d6cc20f.fc547e",
        "type": "inject",
        "z": "affb634f.32158",
        "name": "Positive",
        "topic": "",
        "payload": "I am very pleased with the service.  This is an excellent product!",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 100,
        "wires": [
            [
                "850354bc.da5018"
            ]
        ],
        "info": "The text of a positive sentiment message."
    },
    {
        "id": "b953b022.bf91a",
        "type": "inject",
        "z": "affb634f.32158",
        "name": "Negative",
        "topic": "",
        "payload": "I am not happy.  The product did not meet my expectations.",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 160,
        "wires": [
            [
                "850354bc.da5018"
            ]
        ],
        "info": "The text of a negative sentiment message."
    },
    {
        "id": "dd41b34.c87235",
        "type": "debug",
        "z": "affb634f.32158",
        "name": "Debug sentiment output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "sentiment",
        "targetType": "msg",
        "x": 610,
        "y": 100,
        "wires": [],
        "info": "Log the resulting sentiment (contained in `msg.sentiment`)\nto the debug panel for review."
    }
]
kolban-google commented 4 years ago

Are you still having a puzzle? If not, may I close this issue?

kolban-google commented 4 years ago

Assuming resolved.