[Solved] Openhab2 not sending HTTP or MQTT commands

Hi guys,
Recently I’ve been tinkering on an integrated wall switch + temp/humidity sensor build

It uses a hi-link transformer to power an ESP8266, which reads a sensor and switches a relay. This is done using a modified script from this tutorial:
OpenHAB, MQTT, Arduino and ESP8266: Part 3: Hardware: Arduino with Ethernet Shield

My main problem is, I can’t seem to get openHAB to send commands! I already built two wi-fi dimmers for my aquarium, which worked perfectly before I started poking.

In the following files, only the lines regarding lamp1 have been added. The others were from my previous project, and worked fine. It’s like openhab just doesn’t send out http or mqtt data.

The files are correctly configured, as openhab doesn’t throw me any errors regarding them, and I can see them switching in the events log. I know the ESP8266 is doing it’s thing mostly right, because I can see it’s connection notification (“Switch Online” pop up in the /home/greenhouse/esp8266_25 mqtt subscription, while on the other hand nothing happens when I flick switches in openhab (no mqtt messages on the respective channel appear).

Getting a bit frustrated as i’ve already tried this with openhab2 stable, beta and snapshot builds. And the openhab.log file does not offer many clues, except for this error:

 [WARN ] [eclipse.jetty.servlet.ServletHandler] - /basicui/app
java.lang.IllegalArgumentException: Subscription 5cb37083-aacc-4665-b836-b15cf83683c2 does not exist!
	at org.eclipse.smarthome.io.rest.sitemap.SitemapSubscriptionService.setPageId(SitemapSubscriptionService.java:172)[118:org.eclipse.smarthome.io.rest.sitemap:0.9.0.201703021530]
	at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:147)[198:org.eclipse.smarthome.ui.basic:0.9.0.201703021530]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[82:org.eclipse.jetty.servlet:9.2.19.v20160908]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[82:org.eclipse.jetty.servlet:9.2.19.v20160908]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[173:org.ops4j.pax.web.pax-web-jetty:4.3.0]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[80:org.eclipse.jetty.security:9.2.19.v20160908]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[173:org.ops4j.pax.web.pax-web-jetty:4.3.0]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[82:org.eclipse.jetty.servlet:9.2.19.v20160908]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[173:org.ops4j.pax.web.pax-web-jetty:4.3.0]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.Server.handle(Server.java:499)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[81:org.eclipse.jetty.server:9.2.19.v20160908]
	at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[72:org.eclipse.jetty.io:9.2.19.v20160908]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[84:org.eclipse.jetty.util:9.2.19.v20160908]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[84:org.eclipse.jetty.util:9.2.19.v20160908]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

my default.items file:

Group All

/*ACTIVE GROUPS */
Group:Dimmer:AVG                Aquariums

/*LIGHTS*/
Dimmer	Malawi		"Malawi"        <light>         (Aquariums)     { http=">[*:GET:http://10.0.1.13/led/%2$s/]" }
Dimmer	Tanganyika	"Tanganyika"	<light>         (Aquariums)     { http=">[*:GET:http://10.0.1.18/led/%2$s/]" }
Switch  lamp1           "Greenhouse Light"   <light> (Greenhouse)            { mqtt=">[broker:/home/greenhouse/esp8266_25/relay/com/:command:on:1],>[broker:/home/greenhouse/esp8266_25/relay/com/:command:off:0],<[broker:/home/greenhouse/esp8266_25/relay/state:state:default"}

my default.sitemap

sitemap default label="default" {
	Frame label="Aquarium Lights" {
		Slider item=Aquariums label="Aquariums"
		Slider item=Malawi	label="Malawi"		icon="light"
		Slider item=Tanganyika	label="Tanganyika"	icon="light"
		Switch item=lamp1 label="Greenhouse"	
	}
}

The sketch running on the ESP

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
void LED_CHANGE();

// LED FET
#define ledPIN    0
#define tempPIN  2

// WiFi Settings
const char *ssid =  "network";
const char *pass =  "psk";

// Start WiFi Server
WiFiServer server(1833);


// Update these with values suitable for your network.
//byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte broker[] = { 10, 0, 1, 14 }; // IP Address of your MQTT Server
byte ip[]     = { 10, 0, 1, 25 }; // IP for this device
// Callback function header
void callback(char* topic, byte* payload, unsigned int length);

WiFiClient wificlient;
PubSubClient client(broker, 1883, callback, wificlient);

void setup()
{
  pinMode(ledPIN, OUTPUT);
  digitalWrite(ledPIN, LOW);
  pinMode(tempPIN, INPUT);
  digitalWrite(tempPIN, LOW);
  Serial.begin(115200);
  Serial.println(" Starting  "); 
  delay(1000); pinMode(ledPIN, OUTPUT); 
  // Setup console
  delay(10);
  Serial.println();
  Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("");
  
  server.begin();
  Serial.println("Webserver started");
  
  if (client.connect("arduinoClient")) {
    
    
    Serial.println("MTQQ Connected");
    client.publish("/home/greenhouse/esp8266_25","switch Online");
    client.subscribe("/home/greenhouse/esp8266_25");  // Subscribe to all messages for this device
  }


}

void loop()
{
  client.loop();
  // Check if a client has connected
//  WiFiClient client = server.available();
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.println("Callback");
Serial.print("Topic:");
Serial.println(topic);
Serial.print("Length:");
Serial.println(length);
Serial.println("Payload:");
Serial.write(payload,length);
Serial.println();

  if (strcmp(topic,"/home/greenhouse/esp8266_25/relay/com/")==0) { 
    if (payload[0] == '0') {
      digitalWrite(ledPIN, LOW);
      Serial.println ("Turning OFF");
      delay(100);
      client.publish("/home/greenhouse/esp8266_25/relay/state/","OFF");
      }
    else if (payload[0] == '1') {
      digitalWrite(ledPIN, HIGH);
      Serial.println ("Turning ON");
      delay(100);
      client.publish("/home/greenhouse/esp8266_25/relay/state/","ON");
      }
   }
}

You might need to use all caps ON and OFF after “command” in the outgoing MQTT Item config strings.

So, eventually I found a nice tutorial where I found the missing link (litteraly). So I thought I’d refer others here as well. I needed to define an event bus for MQTT messages to be piped through. See this topic for info: