Can i run OpenHAB in parallel with other websites which control an ESP8266 separately but on the same Raspbery Pi? What's the best way to do this?

I have set up OpenHAB to control some hue lights using this tutorial and i plan to continue by making my own sensors and buying some ZWave stuff.

But right now i am working on a separate project. I want to use an ESP8266 to control a set of peristaltic pumps by controlling transistors to turn them on an off. Essentially all i want to do is send commands from a website to turn the GPIO on the ESP8266 on/off.

The catch is that this website will contain a database of all different drinks and whatnot. The pumps which the ESP8266 controls will be connected to different cocktail ingredients, essentially making a cocktail mixing robot. The website needs a database of drinks so that you can tell it what ingredients you have and it will show you what drinks you can make with them. It will then send the commands to make the drink to the ESP8266 (for instance if you have gin, tonic, vodka, and orange juice it will display gin and tonic or a screwdriver. If you select Screwdrivier it will send (Pump1:50mL; pump2: 150mL) to the ESP which will interpret this and control the pumps.

Since the website will be a bit complex needing a database and such, it will need to run on its own server.

Heres the meat of my problem: I don’t want to have to buy a new raspberry pi for each project that requires a webserver, i already have two (one of which is dedicated for 3D printing). I want to know if its possible to run OpenHAB alongside this website and if so how would i go about differentiating the two when i type raspberrypi.local (or the IP of the raspberry pi). Is it as simple as running the other website on a different port (right now OpenHAB is running on port 8080)?

Even though openHAB is running on port 8080 i dont need to enter “:8080” at the end when i type into my browser, so i am concerned openHAB is controlling all incoming traffic.

What is the best way of setting up this website on the same raspberry pi (is it even possible?).

Secondly, if you guys know anything about this whats the best way to send instructions to a ESP8266 from a generic website running on a server?

You can use lighttpd, nginx or even apache2 in parallel to openHAB as long as you take care of different ports (easy enough, as openHAB uses 8080 and 8443 per default). I would suggest not to use apache2 as its footprint is measurably bigger than lighttpd.

Did you see this topic? There are even more (though mostly openHAB specific) here

Normally communication with the ESP8266 through openHAB is done through the mqtt binding:


As a broker you could use mosquitto.

An item would then look like:
Number nodeMCU_Temp "nM Temp [%.1f °C]" { mqtt="<[mosquitto:ESP8266/temperature:state:default]" }

If you want to use an alternative firmware you could use ESPEasy.
To control a relay the command would look like:
http://<ESP IP address>/control?cmd=GPIO,<pin>,0
so it is a simple link which could be implemented into a website.

I’m ready to be invited as soon as your robot is ready for use :grinning:

thanks for the links! i will look into these

i know that MQTT is used to communicate to ESP8266 with openhab, but the bar robot will not be an OpenHAB device. Instead it will be controlled separately from a website that i want to run on the same raspberry pi as openHAB.

Haha if you’re in the Sacramento. CA region (or Bay Area even) i’d be more than willing to invite you over!

Then the ESPEasy firmware for the ESP8266 could be one choice, you could set up some nice http link structure to mix your drinks.

No, unfortunately 6000 miles away from that place. But I visited your area several times and it’s one of the nicest places I have seen in the US.

Cheers.

@lotatronics:
but why not integrate your cocktail mixing robot within openHAB.
Just give a selection of Cocktails within the sitemap, which starts mixing.
Within openHAB you can “count” your ingridients and have something like a supply Management: if vodka is near the end, the next bottle is ordered…
The list of cocktails within the sitemap can be configured by “visibility”, if an ingridient is out of stock…

Greets,
Andreas

PS: have you some more information of your cocktail robot?

The reason i want it to be separate from openHAB is because i have a lot more freedom to make a nice web interface outside the bounds of OpenHAB’s Java interface. I have never tried making a custom openHAB overlay and i feel like that would be too much to do for right now. Eventually I do intend to integrate it into the openHAB but that’s for when i have a better understanding of how to make a good graphical openHAB interface for the drink menu.

What info about the robot do you wanna know? It’s actually a very simple design, just a series of TIP120 transistors that control a 12v 4A power supply for a series of peristaltic pumps.

Yes, it is that simple.

That implies that in fact your openHAB is actually running on port 80 or you have some DNS or edits to your hosts file on your clients or something that fills in the :8080 for you. For example, I have port forwarding set up in my router so if I go to my DynDNS address (without specifying the port) it automatically forwards it to 8443 (the HTTPS port OH listens on by default). There is no mechanism for OH to “control all incoming traffic.” It only sees traffic on the ports it is listening on.

So the real thing to figure out is what have you done, inadvertently or on purpose set something such that you don’t need to supply the :8080.

You should only have to worry about setting up a reverse proxy if you want to avoid manually adding the port to the URL.

NOTE: OH by default listens on 8080 (HTTP), 8443 (HTTPS), and 5555 (Mgmt Console). As long as you avoid those ports with your web server there won’t be any conflicts.

I’ve successfully run simple websites and web based UIs in parallel with OH many times.

As for the best way to send instructions to the ESP8266, there seems to be two main popular ways, both of which @sihui describes: MQTT or an HTTP REST API.

Lots of people have strong arguments in favor and against each one but I think it ultimately boils down to personal preference. I probably would have standardized on HTTP REST in my setup had I not already set up an MQTT broker to get the Mqttitude binding to work. Since I had that set up I just kept adding more and more to that bus.

Sounds like a really fun project. I hope you get it working!

Besides your trouble with your ports …

From a device point of view you will always have a dependency between your cocktail machine (ESP) and your webserver (Raspberry).
Wouldn’t it be a better Approach to cut this dependency by having all Information (and database) about the cocktails within the ESP8266 and just have a pretty website to choose the cocktail?

Maybe the ESP8266 itself is capable of serving your pretty web Interface… Memory should not be a problem with ESP…

Just more confusing ideas…

Andreas

ideally this is the best solution, but i am not sure if the ESP can have a nice javascript front-end. not to mention the database of drinks and images

It makes one wonder if a Pi or some other board computer might be a better overall solution rather than the ESPs. That would make your entire barbot be more self contained and independent. For integration with other devices you can implement a REST API easily.

In terms of javascript, that is executed on the client, not the server, so the ESP can serve javascript all day. Its just text from its perspective.

I don’t know how much storage is on the ESP so the DB may be a problem. The size of the webpages and images could be a problem which is why it feels better to drop the ESPs and wire up your pumps to a Pi and host everything there. That way you get the capability in a more self contained package.

im leaning more and more towards doing just that and getting a pi. It still leaves me with the question of what framework i should use. So far i’m having three main ones suggested to me: Flask and Django if i go with python and node.js if i go with javascript.

Working with the GPIO library on the Pi is really easy in Python. You can see an example here (it is a script I run on my remote Pis to send/receive info with OH). The gpioSensor.py file shows how to interact with them through WebIOPi and the rpiGPIO* files show how to interact using the native Pi GPIO python library.

Could you please explain how to do this? I’m new and at a loss. I have a raspberry pi 3 that I’ve installed nginx and php 7 on and I have a small website I’ve built with grav on it. I then installed openhab to control some lights and fans with a few esp8266. However when I go to the link to see the openhab demo site it keeps routing back to the website that’s hosted on the pi, I’m stuck.

I know what nginx does and what it is capable of. But I can offer no advice on how to set it up. Assuming defaults when you go to http://localhost it should bring up nginx. When you go to http://localhost:8080 it should go to openHAB.

If it doesn’t it means there is something with how nginx is set up such that it is listening on port 8080. In that case you should be seeing errors in openHAB’s logs indicating a Bind exception because nginx is already using the port openHAB needs.