Connecting to ESP8266 usinf REST API's from open HAB


(Pretheep K P) #1

Can someone guide me to an example to connect to ESP8266 (connected to a relay switch) using RESTAPI’s. I dont want to use MQTT, hence askng for REST API’s


(Garrett Porter) #2

Aw man, I clicked on this thinking “oh that’ll be a cool tutorial to read!”

I’m pretty sure the tutorial flag is meant for more complete tutorials.

As for how this would work, which firmware are you using/planning to use on the ESP8266? The REST API is pretty standard, you ought to be able to use the HTTP binding once you’ve got a firmware picked out.


(SiHui) #3

Moved to “Hardware-DIY” :grinning:


(Pretheep K P) #4

Oops sorry, I thought we could request for tutorials too :slight_smile:


(Pretheep K P) #5

Currently I am using thru MQTT to communicate, but it doesnt seem to be reliable. It crashes often. So need another reliable option. Havent thought about firmware. Any suggestions? I am using RPi as the OpenHAB server and using latest version of OpenHAB. I have nodeMCU module which I am using to communicate to manage few relays connected to it.

So please treat me as a beginner and any guidance for REST API would be helpful.


(SiHui) #6

I switched to MQTT because HTTP was not reliable :sunglasses:
The most support you will get in this forum is with Tasmota and ESPEasy firmware.


(Vincent Regaud) #7

This should get you started:


(Volker Bier) #8

I have implemented a sketch that can connect to openHAB and allows to control relays on an ESP8266:

It is not extensively tested as I have not yet started using it. The plan is to use it with rules for garden watering.


(Garrett Porter) #9

Which software are you currently using on the ESP8266?

Depending on which software, you have options to make MQTT more reliable. If your quality of service is 0 then try setting it to a 1 or a 2 - this will help the messages go through.

Do you have any idea where the messages are getting lost? I would assume you use Mosquitto broker (most popular around here) - is your broker running on your OpenHAB machine or another machine?

I used HTTP calls for a bit on ESPEasy firmware - the firmware crashed often leaving me to do my own hard reset of the device. I switched those to custom arduino sketches with MQTT.

An additional thing to check would be to check that the nodeMCU has a solid wifi connection. If it doesn’t then no change of protocol will be helpful. Your best option is probably set your quality of service (QoS) to 2 and hope for the best.

TL;DR: you might be able to fix your MQTT troubles instead of reprogramming everything, we need to get to the root of the problem.


(Pretheep K P) #10

Hi,
My issue is that MQTT server suddenly stops. MQTT is running on OpenHAB machine itself (Running in a RPi3). Below are the entries in the openHAB log. MQTT suddenly stops and only way to get out of this is to restart RPi3. Its happening every day. So I have restart the RPi3 everyday. I am using generic ESP8266 board in Arduino IDE and lua script. I am not sure if this answers your question about software used.

_2019-02-08 18:18:38.594 [hingStatusInfoChangedEvent] - 'mqtt:broker:8e589a87' changed from OFFLINE (COMMUNICATION_ERROR): Unable to connect to server to OFFLINE_

_2019-02-08 18:18:38.629 [hingStatusInfoChangedEvent] - 'mqtt:broker:8e589a87' changed from OFFLINE to OFFLINE (COMMUNICATION_ERROR): Unable to connect to server_

(Vincent Regaud) #11

What broker do you use?


(Pretheep K P) #12

I use MQTT Embedded Broker. Below is how my Paper UI looks like

When I create a Thing I select the following in sequence

MQTT Thing Binding -> Generic MQTT Thing -> Under Bridge select MQTT System Broker as shown in pic below


(Pretheep K P) #13

Thanks. But I couldnt make out what is explained in the readme document. It says about some code, but not mentioning where I have to write the code. Should I use Arduino IDE to write code and upload it to my ESP8266?

Sorry, it would have been great if it was explained a bit more easier for beginners like me. I dont use circuitIO too, I just use Arduino IDE and upload a code to ESP8266.


(Volker Bier) #14

You don’t need to write code, the code is already written. You have to compile it with Arduino IDE and upload it to the ESP8266. What is circuitIO?


(Pretheep K P) #15

Sorry, Ignore the circuitio line, My bad. :frowning:

There are so many ino files, which one should I use? Any library i should install? If yes, then is there a zip file for that library?


(Volker Bier) #16

I have added the library dependencies to platformio.ini and to the readme.

From a quick look at the Arduino IDE documentation I could not find out if the files can be compiled with it, as you need all of the files. I personally use Visual Studio code with the PlatformIO IDE add-on. You should be able to open the folder with it and clicking on compile builds the sketch. I have justed cloned the repo and tested it.

The hardware that is used might need to be changed (I use a Wemos D1 mini).