koalazak / rest980

REST interface to control your iRobot Roomba 980 via local server on your lan.
MIT License
293 stars 62 forks source link

Great work Koalazak! #1

Closed roelbroersma closed 7 years ago

roelbroersma commented 7 years ago

You already made this project, great work!!

I am currently looking to make a Docker image and want to publish it. So anyone can downloads it, set 3 parameters and Run it!

I think the way to do it is to download the docker image: Google/nodejs (latest), Then download rest980 in it. Then make some variables and then commit and publish the image.

Now everyone would be able to tun it from their Synology or even directly in Hyper-V (which supports docker images in the latest version).

Note: The docker image can be 'auto updated' but that doesn't need to happen often.. Because the rest980 can/is already auto-updated within the nodejs.

Do you have any ideas or feedback? Or do you want to publish it under this Github account? Tell me what you think about it.

koalazak commented 7 years ago

Hi @roelbroersma, its a good idea! feel free to make a pull request to update README.md with a how to use the docker image. Is the image too big? we can host the image in this repo too

roelbroersma commented 7 years ago

Hi @koalazak, I'm not that familiar with Docker. But I think it is best to register it at: https://regitry.hub.docker.com That 'repository' is included by default on a lot of devices (Synology,..etc..) It is the most common.

I think we should host a 'Dockerfile' there, which is just a TXT file with some lines. As soon as you install the docker image, it will download that TXT file and download all the needed files/images which are included in that file.

To keep things organized. Do you have a Docker ID ? I think it is best that you (as author of this software) create it, under the name Koalazak.. Then it's easy for everyone to find and better than when I create a DockerID 'roellerbroersma' ;)

koalazak commented 7 years ago

Ok i have a new docker id with koalazak username. Sendme the txt when you finish it :)

roelbroersma commented 7 years ago

I read a lot about it.. studied some examples.. and think this should be at least in it:

# Use latest long-live-stasble-docker image
FROM node:latest

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app   # or something like WORKDIR $HOME/app

# Set environment variables
ENV HOME=/home/app
USER app

# Install the express framework (App dependency)
ADD package.json package.json
COPY package.json /usr/src/app/
RUN npm install --save express

# Bind/Listen to port 3000
EXPOSE 3000

# Start the REST interface!
CMD [ "npm", "start" ]
roelbroersma commented 7 years ago

Maybe someone with a bit more Docker knowledge can help us a bit out here..

koalazak commented 7 years ago

mmm i think the Install the express framework lines are not necesary. Instead we need to git clone this repo and run npm install inside cloned folder. (this repo install express as dependencies as well). Then we need a way to create the default.json file with user credentias. Do you know how? maybe setting some enviroments variables when run the start command. ( I use config module in rest980 to handle the config file: https://github.com/lorenwest/node-config/wiki/Environment-Variables)

koalazak commented 7 years ago

something like this:

# Use latest long-live-stasble-docker image
FROM node:latest

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install rest980
RUN apt-get update
RUN apt-get install -y git
RUN git clone https://github.com/koalazak/rest980.git ./
RUN npm install

# Bind/Listen to port 3000
EXPOSE 3000

# how the user complete this info?! <------- ????
ENV NODE_CONFIG='{"blid":"mypass", "password": "mypass"}'

# Start the REST interface!
CMD [ "npm", "start" ]

what you think?

roelbroersma commented 7 years ago

@koalazak, sorry for being offline last few days..

In the dockerfile you can set environment variables for PASSWORD, ID, etc. using the ENV statement. When you use the variables, you have to write them in the Dockerfile either with $variable_name or $(variable_name)

When you run the dockerfile from commandline OR when you run the docker image from an synology platform, you can sepcify Environment variables which overrule the ones in the Dockerfile. This is what makes it flexible. So the user will load the image and set the environment varibles for PASSWORD, ID, etc. in the synology interface, see screenshot below

image (this is a Docker image which is a REST interface for my wifi-thermostat (Nefit Easy) for my Heating)

So we can declare PASSWORD, ID, etc. in the dockerfile and then run the docker image with: $ docker run -e "PASSWORD=xxxxxx"

References: https://docs.docker.com/engine/reference/builder/#/environment-replacement https://docs.docker.com/engine/reference/builder/#/env

roelbroersma commented 7 years ago

Btw. Do you have a Synology?

koalazak commented 7 years ago

Great! I push changes on rest980 to use enviroment variables for config. And with this docker file seems to work fine:

# Use latest node
FROM node:latest

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install rest980
RUN apt-get update
RUN apt-get install -y git
RUN git clone https://github.com/koalazak/rest980.git ./
RUN npm install

ENV BLID ''
ENV PASSWORD ''
ENV ROBOT_IP ''

ENV PORT 3000

EXPOSE ${PORT}

# Start the REST interface!
CMD [ "npm", "start" ]

I try this file using:

docker build ./
docker run -e BLID=test -e PASSWORD=test -e ROBOT_IP=192.168.1.104 7e02fa76daf6

where 7e02fa76daf6 is the buit image

Can you try? if its works i publish this dockerfile on my docker account.

(i dont have Synology)

regards!

roelbroersma commented 7 years ago

I will test it, but my Synology is @home (a few hundred KM away from were I am now) and it is turned off because there is something with the power... Will test it within 48hours.

roelbroersma commented 7 years ago

I tested this weekend (and today) I have plenty ot time:)

Can you please publish the Dockerfile to your account? In the Synology, I cannot add just a dockerfile. I have to Search it from a Repository... :( So if you can please publish it. I will put it onto the Synology's docker.

koalazak commented 7 years ago

done! use koalazak/rest980

roelbroersma commented 7 years ago

I can find it in the Docker's repository on Synology :)

image

It is downloading now...: image

koalazak commented 7 years ago

annnd!? it works? :p

roelbroersma commented 7 years ago

It's still downloading... for some reason it's quite slow past days..

keep you updated!

roelbroersma commented 7 years ago

BTW. I'm just reading all the actions / methods. But I can't find how to get the 'actual picture with the map'. Is it a downloadable image which is updated every X seconds.. ?

koalazak commented 7 years ago

the map feature is not published yet.

roelbroersma commented 7 years ago

Another question: Is this docker container 'self updating'? We can make it self-updating with the latest REST980 (and underlying Dorita980). I saw on: http://stackoverflow.com/questions/26423515/how-to-automatically-update-your-docker-containers-if-base-images-are-updated that they use a little script (actually a few lines of code) to check if it is running the latest version.

roelbroersma commented 7 years ago

Downloaded and running.. When calling the Base_IP/port, it gives: {"documentation":"https://github.com/koalazak/rest980","pong":"2016-11-14T16:08:51.719Z"}

(and some mesh on the Docker Terminal itself)

and when calling http://base_ip:port/api/local/info gives:

Error: Endpoint not found. at /usr/src/app/app.js:23:13 at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13) at /usr/src/app/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:330:12) at next (/usr/src/app/node_modules/express/lib/router/index.js:271:10) at /usr/src/app/node_modules/express/lib/router/index.js:618:15 at next (/usr/src/app/node_modules/express/lib/router/index.js:256:14) at Function.handle (/usr/src/app/node_modules/express/lib/router/index.js:176:3) at router (/usr/src/app/node_modules/express/lib/router/index.js:46:12) at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13) at /usr/src/app/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:330:12) at next (/usr/src/app/node_modules/express/lib/router/index.js:271:10) at /usr/src/app/node_modules/express/lib/router/index.js:618:15 at next (/usr/src/app/node_modules/express/lib/router/index.js:256:14) at Function.handle (/usr/src/app/node_modules/express/lib/router/index.js:176:3) at router (/usr/src/app/node_modules/express/lib/router/index.js:46:12) at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13) at /usr/src/app/node_modules/express/lib/router/index.js:280:7

So far,.. everything seem to work. Now setting the environment variables and trying to let the Roomba Drive and stop :)

koalazak commented 7 years ago

nice! it works! The error endpoint not found is because /api/local/info does not exist in fact. Try /api/local/info/mission.

The script you mention is not for generate an auto-update image. seems like it is an external script to check if you have the latests image and if not, download and build the latest. You can use that script externaly, but is not part of the image.

roelbroersma commented 7 years ago

Works great!!! I'm now integrating it in a Gira Homeserver which does REST calls to the REST980 docker image! I will write/update more info soon.

BTW. The map feature, Is it a 'service' which runs in the background updating/overwriting an gif/png every second or is it an image and on top you render the coordinates in the browser (javascript) ?

koalazak commented 7 years ago

nice! my plan is add a path in rest980 where you will see the map and some controls via web in your browser. While the api is in /api/loca/... this new page will be in /map in rest980 server.

When you visit /map the server side start to make getMission calls to get the x,y position every 800ms, sending this data to the browser via websockets. Then in client side, the browser draws each point received in the map (html canvas). No image, just a html canvas. closing this issue

thanks!