MQTT not working, testing with ESP8266

I tried many things since I am new it this. I am trying to keep it simple to find the issue. I was trying with shelly but did not work. Now I am trying NodeMCU ESP8266. I am using proven code I can send
It shows that it is connected

MQTT:
1565133506: New connection from 10.0.0.174 on port 1883.
1565133506: Client arduinoClient already connected, closing old connection.
1565133506: New client connected from 10.0.0.174 as arduinoClient (p2, c1, k15).

ESP8266:
WiFi connected
IP address:
10.0.0.174
Attempting MQTT connection…connected

configuration.yaml:
mqtt:
broker: 10.0.0.155

switch:

  • platform: mqtt
    name: “Switch1”
    state_topic: “ha/switch1”
    command_topic: “ha/switch1”
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    optimistic: false
    retain: true

I added “test here” to the code:
void callback(char* topic, byte* payload, unsigned int length) {
payload[length] = ‘\0’;
strTopic = String((char*)topic);
Serial.println(“test here”); //<< I added
if(strTopic == “ha/switch1”)
{
switch1 = String((char*)payload);
if(switch1 == “ON”)…

I never see that. What else should I check?

I set one of these up yesterday. What software are you using on NodeMCU? I played with Esphomeyaml as it seemed an easy way to add BME280 and BH1750 sensors. Worked right out of the box. But I prefer to use Tasmota so I flashed Tasmota yesterday and it just immediately works.

I have no manual configuration at all for MQTT. I am just using the inbuilt (hass.io) Mosquitto broker and the MQTT integration. I also only use MQTT Discovery. So if you want to make it SIMPLE I would get rid of all that stuff in config and use discovery.

image

Arduino. I am just using it to test for other devices. One of the things I am trying to do the code is already written. https://youtu.be/90n8cZJcFaU