[SOLVED] Looking for help with MQTT and ESP8266 communication

Good, you have the mqtt working!

Now in your items file place the working topic and leave everything else like below.

This is what I have the sitemap file

// Sitemap Files
sitemap home label="Our Home Control Center"
{
        Frame label="Dining_Room"
        {
                Switch item=DR_CPDoor label="Carport"

        }
}

And this is what I have in the items file

Contact DR_CPDoor "Carport Door [%s]" <door> {mqtt="<[broker:home/Dining_Room/DR_CPDoor/Carport:state:default]"}

You may need to change that from Contact to Switch if msg is ON/OFF or change the msg to OPEN/CLOSED and use Text in sitemap not Switch. As a side note, you can use any msg and change it with MAP but for now let get in working on the sitemap.

Ok I changed that to switch.

So just a test this morning, I was sending text out as

“DR_CPDoor/Carport,”, “ON” and then
“DR_CPDoor/Carport,”, “OFF” and it was reading via MQTTfx ok

So now my mqtt statement is this:

 {mqtt="<[broker:home/Dining_Room/DR_CPDoor/Carport:state:default]"}

I changed the text that the wemos is sending out to

home/Dining_Room/DR_CPDoor/Carport (ON or OFF)

Still nothing
 or am i getting too far ahead

When you see it in MQTTfx what does the full msg look like? Need to know the right word to use instead of default.

I don’t use MQTTfx but I was hoping for something more like a script. What do you get if Scripts is clicked up at the top?

There is a demo script

var Thread = Java.type("java.lang.Thread");

function execute(action) {
    out("Test Script: " + action.getName());
    for (var i = 0; i < 10; i++) {
        switchON();
        Thread.sleep(500);
        switchOFF();
        Thread.sleep(500);
    }
    action.setExitCode(0);
    action.setResultText("done.");
    out("Test Script: Done");
    return action;
}

function switchON() {
    out("fountain ON");
    mqttManager.publish("home/garden/fountain", "ON");
}

function switchOFF() {
    out("fountain OFF");
    mqttManager.publish("home/garden/fountain", "OFF");
}

function out(message){
     output.print(message);
}

Try switch in place of default

I’m sorry if this has been corrected and I missed it through the thread but the posted mqtt config file in openHAB had

<broker>.url=tcp://192.168.1.104:1883

Should it have the < > around the broker name?

No it shouldn’t
Post your mqtt.cfg file, please

I hope < > isn’t around broker in the mqtt.cfg, but rereading the thread I can see why you ask.:frowning:

It’s and easy thing to miss. Especially if your new. I remember when I started, mqtt stuff screwed me up for a while, still does sometimes. Tasomota does make life alot easier.

I have removed the <> from around and rebooted the system

<broker>.url=tcp://192.168.1.104:1883

broker.url=tcp://192.168.1.104:1883

This is driving me crazy !!! I can open up putty and use the commend

mosquitto_sub -h <my ip>  -p 1883  -t MK-SmartHouse/Security/MKDoorSensor1

and see it is displaying either OPEN or CLOSED in a scrolling window.

If ANYONE can help me get this one thing working, I would be grateful. I haven’t tried loading Atom or anything to get Tasmota running. One time I d/l’ ed the file and unzipped it. In the process, I got all kinds of errors about lengths of file names and then it tried getting through my firewall. So I stopped that and deleted everything to do with that.
If I am receiving data back from the mqtt server, what is needed to make this work ???

I wish someone would do a video or a write up to show how to setup mqtt, connect one switch with code and make it work. I followed everything from the MK-SmartHome site, except missing the above mentioned error, and still cant get it to work. Now I didn’t set it up to to send an email when the door was open, so I was hoping to show the door open and close on the display when a switch actually opened and closed.

@johntech If you changed back to the MK script then use the item that’s working with mqtt via the terminal.

Sorry about not catching the < > around the broker earlier.

Contact MKDoorSensor1 "Side Door [%s]" <door> { mqtt="<[broker:MK-SmartHouse/Security/MKDoorSensor1:state:default]" } 

@johntech one more suggestion is to open your OH log in a separate tab. Place only the one item in your items file.

Contact MKDoorSensor1 "Side Door [%s]" <door> { mqtt="<[broker:MK-SmartHouse/Security/MKDoorSensor1:state:default]" } 

Then using your wemos open and close the contact. You will see this displayed in the log. After this you can create the sitemap and see the change happening there as well.

I can manually toggle the switch on the screen and it will show in the log. I was hoping to use the code in the ESP8266 to toggle the switch on the screen. Maybe the OH code isn’t written to do that, From the MK site it was supposed to send a message if the door was opened. I checked my code in both item and sitemap and it matches what is being sent from the 8266. and the <> were not in either file listings.

I have Atom loaded and sitting at the welcome screen, now trying to figure out what to do next to get sono, whatever it’s called, loaded and program the 8266.

This is just making more confusing!! I don’t understand, If I am getting data TO the mqtt server AND reading it back then there must be a missing “hook” in the SO code that is not capturing the data and displaying it.

This will show how to download the tasmota and setup use PlatformIO.

Then read and follow these instructions for using wemos.

If you can see this in your OH terminal then try putting the item in the items file like this:

&&^**&^&)_(&^( !!!

I went back and looked at that code AGAIN and noticed I had left the - in between MK and DoorSensor1

MK-DoorSensor1 when it should have been MKDoorSensor1
^^^^^^^
That is what I ment way earlier in these posts when I said it was confusing about one section of code had the - and the other didn’t!!!

OK NOW it is displaying the OPEN/CLOSED messages in the log and the error for the broadcast message, which I didn’t set up.

So now I need to edit the rules file to show open/closed door.

****YEA !!! *****
I removed the code for sending a message out and now the door is showing open and closed on the screen!!! Now I can get back to figuring out the rules I want for the switch. Like turning the power button on the screen red when the door is open.

Thanks H102 for sticking with me through all of this!!

This is good, OH and the wemos is communicating via mqtt!!! Not sure what you mean by broadcast message.

A rule to show open/closed where? If to see on BasicUI you only need a sitemap file with the name of your item MKDoorSensor1