Home Automation at Home Part 1: ESP8266 & MQTT

Поділитися
Вставка
  • Опубліковано 31 гру 2024

КОМЕНТАРІ • 297

  • @ItKindaWorks
    @ItKindaWorks  7 років тому +2

    Got a question or something to add to this video? Or even an idea for a new tutorial/video that you'd like to see? Check out the ItKindaWorks forums at itkindaworks.com/forum/

  • @yuriikurschner1972
    @yuriikurschner1972 8 років тому +40

    For those who have a problem with error:
    ESP8266_SimpleMQTT.ino:25: error: 'callback' was not declared in this scope
    PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
    ^
    exit status 1
    'callback' was not declared in this scope
    You just need add:
    // Callback function header
    void callback(char* topic, byte* payload, unsigned int length);
    ABOVE
    PubSubClient client(server, 1883, callback, ethClient);
    Body of callback function stay on his place.
    No need change Arduino version.

    • @lisnjay
      @lisnjay 8 років тому

      Thanks!!

    • @sujankarki4983
      @sujankarki4983 7 років тому

      Nice video. You may also want to checkout the review of home automation on my blog at *bradleyreviews. com/home-automation-review/* Thanks, Dorian.

    • @ajinkya1412
      @ajinkya1412 7 років тому

      thank you

    • @pjotr5009
      @pjotr5009 4 роки тому +3

      Still got this error. How to solve this ?

    • @zachreyhelmberger894
      @zachreyhelmberger894 4 роки тому

      WOW!! It compiled!! God bless the Internet! Lets see if it works now...

  • @007travelbug
    @007travelbug 8 років тому +2

    best video I have seen yet on mqtt and pi. Thx! Once I get into it I am sure I will have questions. Goal - temperature /humidity data logging from multiple arduino/esp8266s etc collected on pi and then stored/graphed/trended etc to start to use historical data (and multiple sources like outdoor temp/indoor temp/weather forecast etc. to do some predictive logic to determine if better to open window, or turn on furnace/ac etc, and also see "lag" between outdoor temp and indoor temp changes (thermal inertia?) of my house, greenhouse and chicken coop... (crazy I know)..then on to monitoring soil moisture levels for watering with irrigation logic (predictive/reactive) vs just irrigation on a timer (dumb). Ultimately full home automation+ greenhouse/chicken coop/beehive/workshop automation...
    Hope to learn more from you. Thanks again!!

  • @bgable7707
    @bgable7707 5 років тому

    EXCELLENT, very nice Clean code! Simple and straight forward explanation and demonstration of MQTT. I'm looking forward to the other videos!

  • @MrAppDev
    @MrAppDev 7 років тому +3

    Thank you so much! The only good tutorial i found on MQTT after hours of googling!

  • @northshorepx
    @northshorepx 8 років тому +2

    Thank you for a great video. Your pace and delivery made understanding this topic very easy. If I could recommend a small thing please? It's not a biggie, but when showing code most of the screen was empty and the code it self was quite small. Perhaps you could zoom to the code a bit more please? However as I said this was an otherwise excellent tutorial and I've subscribed to your channel as you obviously know what you're talking about, and present it very very well. Thank you again!

    • @ItKindaWorks
      @ItKindaWorks  8 років тому +4

      This was one of my first videos... I've gotten a bit better with my newer videos :)

  • @rodrigosantos4160
    @rodrigosantos4160 7 років тому

    Great tutorial!!!! The best explanation about MQTT I've seen so far. Thanks!

  • @corydiehl764
    @corydiehl764 6 років тому

    Finally got it to work. If anyone is struggling with installing the packages try "sudo aptitude -f install package " instead of apt-get.
    Also, this works on the nodeMCU as well, just refer to the GPIO pins

  • @mmajstruk398
    @mmajstruk398 6 років тому

    That's an easy explanation of configuring mqtt with esp8266 - exactly what I was looking for.
    I'm have already mosquito and Node-red running on mi Pi 3, now it's time to program the ESPs. I hope that next videos will help me as well. Thanks

  • @sramilli
    @sramilli 8 років тому +2

    For all of u having the compilation error --> 'callback' was not declared in this scope
    One workaround is to just move the declaration above where you use it
    Like this:
    void callback(char* topic, byte* payload, unsigned int length) {....stuff.....}
    before
    WiFiClient wifiClient;
    PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);

  • @stokseelalleen1913
    @stokseelalleen1913 8 років тому

    Fantastic tutorial thank you. I'm gonna give this a try when I get some time, but so far it's the best MQTT material I've seen for getting started. Cheers

  • @stevemorse5052
    @stevemorse5052 4 роки тому

    Well done tutorial, Thanks, it worked (with one problem noted below) on my new NodeMCU E12 from Banggood.
    Get your MQTT broker up and running and tested before you start this. It helps, and takes one variable out of the equation!
    Use the topics /house/light1 and /test/confirm for testing the MQTT broker.
    The 2 libraries, I believe they can be installed via the library manger now, no need to futz with zip file (unless you want to)
    For those who have a problem with error:
    ESP8266_SimpleMQTT.ino:25: error: 'callback' was not declared in this scope,
    prefect4 years ago

  • @CesarLopezBestNetworksInc
    @CesarLopezBestNetworksInc 7 років тому +1

    Just perfect! Thank you so much. I am starting to use the 8266 and find it just the perfect to do my projects! I did start with a garage opener using Blynk, but from what I see I should be able to use my own R-Pi unit. I wish I had more time to play with this!
    Thanks again.....
    Cesar

  • @chuc2rk
    @chuc2rk 8 років тому +1

    Very clear guide. I'm a beginner. Very happy when watch your video. Thank you very much!

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +Chức Nguyễn You're welcome, glad you like it :)

  • @spanout
    @spanout 7 років тому

    Brilliant tutorial. Really explains end to end mqtt and esp8266. Thank you

  • @davidkempton2894
    @davidkempton2894 8 років тому +1

    Not tried it yet but this was a great intro to Pub/Sub using the ESP. Thanks!

  • @MMphego
    @MMphego 8 років тому

    Thank you for a great tutorial, I just got my ESP8266 module today and your tutorials were very handy.

  • @D-Khaz
    @D-Khaz 8 років тому

    @ItKindaWorks Great beginners video! I'd like to ask if you can make a more complete MQTT video? Specifically I'd like to learn more about security MQTT. I'd like to understand the security concerns around making my MQTT server accessible from the WAN so I can communicate with it while remote.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      Hey @poldim sorry for taking so long to get to this! I'm probably not the best person to ask about security, I would be happy to make a more in depth video outlining the MQTT protocol but I dont know as much about the security side of things as I should to talk in depth about it. What I can tell you is that the PubSubClient library doesn't implement any security at all so it would be a bad idea to take the code outlined in these videos and direct it to a public IP as it would all be cleartext. MQTT as a protocol does support TLS however so it's not out of the question. Take a look at this article for more information www.hivemq.com/blog/mqtt-security-fundamentals-tls-ssl. I believe that the Adafruit MQTT client which is under quite a lot of development may support TLS and may be more suitable for WAN communication as it's built to work with their cloud platform. You can check that out here: github.com/adafruit/Adafruit_MQTT_Library
      Again sorry for taking so long to respond.

  • @purple.intermedia4493
    @purple.intermedia4493 6 років тому

    For those who have a problem Connecting to Broker with User & Passwort:
    Just Change "" if (client.connect((char*) clientName.c_str())) "" to "" if (client.connect("arduinoClient", "USER_NAME", "PASSWORD")) "" and remove the client name block with ""// Generate client name based on MAC address"" Just give it a name.
    Good Video!

  • @microsurf128
    @microsurf128 7 років тому +1

    Just spotted
    Юрий Кушнырев post. Thank you, it was driving me mad :-) All working now.

  • @nicksparks3543
    @nicksparks3543 7 років тому

    Bloody marvelous, fantastico...mine worked straight away after doing the minor tweeks with defining the callback before pub. Got the two windows up on RPi3 and I'm using Wemos D1(Arduino size). also I only used the sudo apt-get mosquitto(all repos) It's blooming amazing when this kind of thing works!!!!...................... Thankyou!! ..................
    Arduino 1.8.2 IDE is what I'm using too.

  • @shodanxx
    @shodanxx 8 років тому +1

    Hi, did you try making your mqtt sensor/light to work off an 18650 lithium battery ? I think I've got the power supply squared away, but how do you go to sleep (probably DTIM 3 light sleep mode) while still getting mqtt updates and using the least amount of battery ? Like 15 seconds sleep and then checking for mqtt messages inside like 300ms and then going back to sleep ? Can it be done ?

  • @danielsabag5294
    @danielsabag5294 6 років тому +1

    Great video, simple and well presented. thank you

  • @thestevenbell
    @thestevenbell 8 років тому +1

    Thank you for posting this vid. Exactly what I needed to get started.

  • @googleuser6875
    @googleuser6875 7 років тому

    Glad to see it went well for some. But I hit a brick wall. I could publish to a subscribed terminal window both on the PI fine. After uploading the sketch to the 8266, on the serial port I could see it logging on to my wifi. Then I could see "MQTT connected." After that.....nothing. No response to the terminal window, no led action, and no output to the serial monitor. Any suggestions ? Using:
    RPi 2b w/raspbian pixel: Arduino IDE ver 1.8.4: 8266 ESP12E generic module.

  • @LuisLopezCool
    @LuisLopezCool 8 років тому

    Hi man.. excellent work... I was playing with the esp8266 for a while and I found it is no so stable ... when I use it for light a simple led it works great but for working with a relay and a lamp is resets de module..

  • @dolfdewaal6787
    @dolfdewaal6787 8 років тому

    I tried the example from this video, but compiling failed with the message :
    exit status 1
    'callback' was not declaired in this scope.
    I am using Arduino IDE 1.6.9 and I used the PubSubClient library from the link in the ino file
    Can you tell me what I am doing wrong ?
    regards,
    Dolf de Waal

  • @marinehm
    @marinehm 7 років тому

    Hey! You've got some really GREAT videos and I think it was you with the OTA updates on Github for the ESP8266. Anyway, I've got my Raspberry Pi3 Hosting HomeAssistant, MQTT. I've connected a Wemos ESP8266 to a BME280 Temp sensor. I had lots of help converting the sensor data to a string value in order to publish to MQTT. I can see the values via Serial Console and MQTT. But on the HomeAssistant dashboard, the values are not displayed. Any suggestions?

  • @nishadnadkarni7874
    @nishadnadkarni7874 7 років тому

    Great video! But I've been having a few problems. I used a wemos d1 mini that has an esp8266 in it so I could use it with the arduino IDE. For some reason the pi publishes the message I sent, with part of the message the d1 sent before, concatenated to it. I don't even know how, they're on different topics.
    Basically, when I sent "hello world" from the d1, and then sent "something" from the pi to the d1, and when I printed that message through serial (on the serial monitor) it was "somethinglo world". It literally concatenated part of the message the pi previously received with the message it sent to the d1, how is this happening? Those are two different messages on two different topics.

  • @usamakhan-yi9fb
    @usamakhan-yi9fb 4 роки тому

    hi, can you explain to me a little bit about MQTT as I'm stuck? I want to send a message from my laptop to node MCU or esp8266. I have an MQTT broker installed on my laptop, so I will use that broker or my self-made server/broker.

  • @barkman1one
    @barkman1one 5 років тому

    Thanks for the video, helped me out a lot. could you tell me how to change the code to use "on" & "off" instead if "1" & "0"? thanks

  • @gyp_gyp
    @gyp_gyp 8 років тому

    ItKindaWorks thanks for this tutorial.
    I'm exploring and adding some function to void loop();
    I set pin 5,4,2 as input and stated as sensor1,2,3, then I created function if 5,4,2 is LOW (connected to ground) each of them publish a topic to homeassistant.
    But it always gave me error, serial monitor gave me status after callback a sensor3 topic, it always attempting connection to MQTT server and created like a bootloop again and again.
    But if I delete a function for sensor3, whole system incl sensor1 and 2 work fine.
    How could this happen?
    Thanks before.

  • @JustinLedvina
    @JustinLedvina 8 років тому

    Thank you! You just made my weekend!!

  • @Popart-xh2fd
    @Popart-xh2fd 8 років тому +1

    The same sketch works on Arduino UNO + ESP8266 ESP-01? Normally I use SoftwareSerial.h to enable WiFi and other AT commands...!

  • @andrewkelsey30
    @andrewkelsey30 8 років тому

    This is a great well explained video, helped me a lot. My only problem is the code, when I put it into my IDE, it comes up with "Call back was not declared in this scope" looked everywhere and found difficult to understand answers, which I am not sure were the answer to this issue, anyone else had this problem ? I can't wait to go on to the next videos once I have got this out of the way.
    Oh, once I do get past this hiccup, the code is going onto a Sonoff swtich...

  • @cristiantalos4042
    @cristiantalos4042 5 років тому

    Great tutorial! Keep up the good work!!!

  • @Fudmottin
    @Fudmottin 8 років тому

    I'll have to look into MQTT. I'll be using I2C for the weather station.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +Fudmottin yeah mqtt is a great easy to use protocol

    • @Fudmottin
      @Fudmottin 8 років тому

      ItKindaWorks Did Apple by any chance adopt that for HomeKit? Or are they using a different standard?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +Fudmottin I don't actually know but I'm pretty sure its a completely custom protocol. Since homekit is proprietary theres not a lot out there about it, but I have been using this reverse engineered hack to use my HA system from my phone/siri: github.com/KhaosT/HAP-NodeJS
      I plan on having a video dedicated to this later on in the series.

    • @Fudmottin
      @Fudmottin 8 років тому

      I see. When Apple unveiled HomeKit, they said they were doing it because everyone was using their own standard. I don't know if Apple intends to license or publish the HomeKit protocol.
      Inventing new protocols seems silly to me. HTTP is a perfectly good protocol for this sort of thing. Heck, Telnet would do.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому +1

      +Fudmottin To my knowledge Apple's homekit is totally proprietary. I think in order to gain access to it you have to actually be part of the MFI program. They require full cooperation at the hardware level. Thats why products like the Philips Hue line had to release a new base station to get use of homekit because apple made them change the hardware in order to allow them to use it. So basically the startup cost to even have anything with homekit is like $40k+ which is ridiculous.

  • @stevegee5877
    @stevegee5877 6 років тому

    Hi, if you are going to point something out in a text based screen, please either increase the font size for the duration of the video or zoom into to the screen. Very frustrating not being able to read it.

  • @nayabinlam
    @nayabinlam 6 років тому +2

    Hello i know this tutorial is kinda old but I uploaded the program and i am having both on Arduino 1.6.9 and 1.8.0 this error message : callback was not declared in this scope

    • @Thrieondesign
      @Thrieondesign 6 років тому

      here is the work around from GitHub github.com/ItKindaWorks/ESP8266/issues/7

    • @top6062
      @top6062 6 років тому

      char* lightTopic = "/test/light1";
      // Callback function header
      void callback(char* topic, byte* payload, unsigned int length);
      WiFiClient wifiClient;
      PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
      void setup() {

  • @siddharthachatterjee4941
    @siddharthachatterjee4941 8 років тому

    Nice tutorial thank you.
    I tried your steps. It works well till the point I opened two terminals - sub and pub. Whatever I pub to a 'topic' the sub to that 'topic' sees that immediately.
    But it does not work on the ESP8266 part there on.
    Also - I did not install mosquitto on a Ras-pi. I did all above on a Digital Ocean droplet. Your Ras-pi and your ESP8266 were on the same home network. But in my case the Digital Ocean droplet is external and has its static IP. ESP8266 is on my home network. Do you think this could be the problem.
    Could you kindly help on this point ?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      Hmm... I'm not sure, I've never done anything outside of LAN but if I had to guess I would imagine it would have to be some routing/firewall issue. You say you can sub/pub from a terminal - I have to ask, are those terminals local to the broker server or are they from your LAN?
      There's no reason that you shouldnt be able to connect over WAN although I do advise against it if it is part of a security system or anything like that. The implementation of MQTT on the ESP doesnt include connection encryption so everything is easy to snoop on. You can do MQTT over an encrypted connection but what is shown in this video has none.

  • @geminischweiz
    @geminischweiz 2 роки тому

    Greetings from 2022. is this system still ok? can i still do it or changed a lot in that time? thx!

  • @blockchainstreet
    @blockchainstreet 7 років тому

    Thanks for this nice video... May I see the previous video? Of this

  • @grangemd1
    @grangemd1 8 років тому

    When I troubleshoot the serial monitor just fills up with Attempting MQTT Connection and MQTT Connected. Is this normal? Should it just keep scrolling through these serial lines constantly?

  • @microsurf128
    @microsurf128 7 років тому

    have trouble with light code where i am getting an error in arduino compiling,
    exit status 1
    'callback' was not declared in this scope

  • @ParthBhat
    @ParthBhat 8 років тому +1

    liked and subscribed..
    just helped me out to figure a small error I was doing since many days on Mqtt side. and still not able to bind openhab and Mqtt.. but thanks a lot..

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      Which version of openHab are you using? I got it to work a long time ago with v1 but I've never touched v2. I might be able to point you in the right direction

    • @ParthBhat
      @ParthBhat 8 років тому

      +ItKindaWorks I guess I didn't try on version 1. but I am trying on version 2.1. it have got really annoying for me as non of the examples online I have don't work for me.
      I run the broker on my laptop.
      edited the openhab .cfg conig file to connect to my broker
      then I have had other command window running with subscribe all
      so, when I press any buttons on my webpage it doesn't show me anything on subscription ...
      even if I individually subscribe to the specific topic I have described in open had that dont work for me.. very much annoyed with that.
      and please check the openhab+mqtt video made by "Make" I tried that example too.. at least to see if my openhab is atleast sending Mqtt messages or not.. but no luck..
      and thanks a lot for your reply

    • @ParthBhat
      @ParthBhat 8 років тому

      +ItKindaWorks
      after thinking and taking your thought of checking the version I went back to 1.7v and tried that and it worked.. i came back to 1.8v and then realised I just copied the actions.mqtt add-on in the folder and not binding.mqtt and I finally made it working.. did some small tweaking with your esp code to work with Ethernet shield and it works great.. now my plan is to run a "Mycroft" open source speech recognition and maybe make a Python script to deploy it on mqtt and to automate the house..
      even you can try that it will be really a fun ..
      thanks again and you have got all my likes thanks a lot..

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      Sorry for going MIA for a couple days, it's great to hear that you got it all sorted out though! That sounds like an awesome project! I have a ton of things on my plate right now but I would love to do something like that at some point. If/when you get yours running, shoot me a message and I might pick it up in the fall for a video - crediting you with the code of course!

    • @ParthBhat
      @ParthBhat 8 років тому +1

      Thanks a lot for your reply again.. :)..
      For sure if I get it working I will update you with that as soon as possible but for now I have to first complete the automation then I have to give it voice , listening and seeing capability.. I'll surely update you..
      Cheers and happy building.. :)

  • @Popart-xh2fd
    @Popart-xh2fd 8 років тому

    Do you know how to use the ESP8266 together with an Arduino Board (Ex.: Uno) and be able to connect trough MQTT? It looks like people only knows to use the ESP8266 alone when it comes to MQTT, for MQTT connections I still haven't saw anyone that have used an ESP8266 as a WiFi module only with sketches uploaded to the Arduino board instead...!

  • @gibo588
    @gibo588 4 роки тому

    wHAT happens if you remove the delay() in the loop? My application does not like delay().

  • @ROMA7836
    @ROMA7836 6 років тому

    Good job ! Howe i can run this topic with Sonoff basic wi-fi relay?

  • @damienosborne3047
    @damienosborne3047 5 років тому

    Great video Man! I'm going to attempt to make a I2C connection back to my Pi using ESP8266 and MQTT. Do you think that would be alot more difficult than this?

  • @callux93
    @callux93 8 років тому +2

    Amazing! Thanks for making this!

  • @StevePrior
    @StevePrior 8 років тому

    I'm just getting started with MQTT and your Arduino code looks like a good example. I am curious why you add part of the timestamp to the mac addr to come up with the client name which would mean that the client name is never the same. I'd have thought that it would be preferable to have the same physical device always generate the same client name so I'd expect the mac by itself to be sufficient. Can you explain why this was necessary?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому +1

      You can do it either way. This code was originally adapted from some of the ESP example code and thats the way they did it. Theres no specific reason though (not that I know of anyways)

  • @zarleyzanard7568
    @zarleyzanard7568 7 років тому +1

    itkindaworks ... awesome job! ty so much!

  • @geman220
    @geman220 8 років тому

    Any chance you could do a tutorial using a servo? Showing how to turn the servo 180 / 360 or whatever based on the message sent from MQTT?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +geman220 I'll put it on my list of videos to make!

  • @looper40
    @looper40 6 років тому

    i cant understand how you place it on the breadboard? pins are shortcircuit?

    • @ItKindaWorks
      @ItKindaWorks  6 років тому

      Where is the short/where are you confused?

  • @sunitapatil381
    @sunitapatil381 5 років тому

    i am getting error like callback is not defined after defining also it is getting

  • @molina3192
    @molina3192 8 років тому

    Hi, thank you for a great video. Ihave a problem during the compilation: I downloaded the PubSubClient.h library from github and I installed it in the C:\Users\.......\Documents\Arduino\libraries path but when I try to compile the program I get this error:
    test2:25: error: 'callback' was not declared in this scope
    PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
    ^
    exit status 1
    'callback' was not declared in this scope
    I copied the code from github but I don't know how I can solve this problem, can you help me please?
    Thank you very much!

  • @arun4life54
    @arun4life54 7 років тому

    if your broker has username and pass, where do you add that in the code?

  • @LuisLopezCool
    @LuisLopezCool 8 років тому

    Could you give me some tips to improve the stability of the module?

    • @Ed19601
      @Ed19601 8 років тому

      a decent psu with maybe a 470uF over the chips powerlines?

  • @RahulKumar-zs2wv
    @RahulKumar-zs2wv 8 років тому

    Nice video. in the video esp8266 is not connected to arduino den how it is programmed.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      I may have skipped over the upload process in this tutorial but heres another one of my videos showing how to upload from the Arduino IDE ua-cam.com/video/chRYm70m2D8/v-deo.html

  • @robertparenton7470
    @robertparenton7470 5 років тому

    Thank You. This video greatly helped me!

  • @dapimor
    @dapimor 7 років тому

    Hello ItKindaWorks, I am trying to connect esp8266 to my mqtt server - mosquito on windows 7, port 1883 is enabled on the firewall, the broker is turned on in service, I can interact with pub and sub via command line up with homeassistant, but I can not connect the esp to the mosquitto, using its code it connects in my local network but not to the broker. Using netstat the port appears by listening. In the esp I put the ip of the machine that is with the broker. Do you know if there are any custom settings that need to be made? Sorry for my English, it is not my native language and it disturbs me a lot in researches :(.
    Thanks for the videos and for disseminating the knowledge.

  • @alvarosouza5565
    @alvarosouza5565 8 років тому

    I'm new to these ESP8266, but I have access to a 12E model, which is inside of the NodeMCU module. I know that these guys can be programmed with the Arduino IDE, the question is: can I use these examples with other versions of the ESP8266, like the one I have, or it'll only work in this model you have?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому +1

      The code should work just fine with any ESP8266 model. Just make sure to adjust the code for whatever pins you plan on using as not all ESP models have the same pins broken out.

    • @alvarosouza5565
      @alvarosouza5565 8 років тому

      Right, I'll check that out. Thanks! BTW, awesome channel. Keep on going :D

  • @sunitapatil381
    @sunitapatil381 5 років тому

    can we control thios throught internet from anywarein the word plz reply

  • @hubbardsw
    @hubbardsw 6 років тому

    How could this be modified to send a string message instead of a byte

  • @PaYtrIxHD
    @PaYtrIxHD 7 років тому

    How about to set up another pi to control his gpios / a led? Can i just use your code and get rid of the wifi code? I think the only thing I have to know, if i can leave the "PubSubClient clien(IP_ADDR_SERVER, 1883, callback, wifiClient);" as it is? What does the wifiClient do?

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      The wifiClient is what pubSubClient runs on top of so you need to have that in order to use mqtt. Why would you not want the wifi code? You need wifi/network for mqtt to work.

  • @DanStone1025
    @DanStone1025 8 років тому

    Hello, fairly new to arduino and thought I'd try your program but I'm getting the following error when compiling the sketch.
    exit status 1
    'callback' was not declared in this scope
    I have used your code without any changes.
    Do I need to add a declaration prior to the PubSubClient info?
    Dan

    • @Thrieondesign
      @Thrieondesign 6 років тому

      here is the work around from GitHub github.com/ItKindaWorks/ESP8266/issues/7

  • @ezzahiabdelghani5220
    @ezzahiabdelghani5220 7 років тому +1

    Hi
    thanks for sharing this video, but when i tested the code i got this error:
    Attempting MQTT .... Failed
    Someone has get the same issue, can you help me please?

    • @snoopymartin
      @snoopymartin 7 років тому

      i get the same error but my mqtt server has a login name and password for protection. It should be entered somewhere in the code. But i don't know where a this moment.

    • @ezzahiabdelghani5220
      @ezzahiabdelghani5220 7 років тому

      Martin Udo
      HI if you want using mosquitto with a password and username, you must to use this command : mosquitto_sub -d -u username -P password -t test
      you can find more details on this link
      www.instructables.com/id/How-to-Use-MQTT-With-the-Raspberry-Pi-and-ESP8266/

    • @snoopymartin
      @snoopymartin 7 років тому

      i know that if i use ssh commands but i want to use this code form the video on my broker with username and password. I can find it for ethernet, but if i copied this in the code for the esp8266 i get an error of it stil won't connect to broker.

    • @danielrobin5488
      @danielrobin5488 6 років тому

      Yeah! Me too. But I'm trying it through windows rather than a raspberry Pi. Although I've copied the same code, I don't know how to fix this issue.

  • @LeafyG
    @LeafyG 6 років тому

    Hello, I am very new to this stuff and I am having an issue installing mosquitto. I am receiving errors
    "The following packages have unmet dependencies: mosquitto :
    Depends: libssl1.0.0 (>= 1.0.0) but it is not installable
    Depends: libwebsockets3 (>= 1.2) but it is not installable
    E: Unable to correct problems, you have held broken packages."
    After searching for hours online, I cant seem to find a fix. Can someone please explain to me?

  • @awaisahmadsiddiqi6505
    @awaisahmadsiddiqi6505 8 років тому

    awesome tutorial, followed this and it worked in first go..
    but i have problem now, if i try to reprogram it , it wont accept AT commands, instead it keep sending debugging data on serial all the time :(
    any suggestions on what could possibly go wrong?

    • @Ed19601
      @Ed19601 8 років тому +1

      if you put any new code in the esp8266 it will overwrite the AT code interpreter.
      So nothing 'goes wrong' you are trying to communicate with an OS that is no longer there.
      If you want the AT coded back, need to load them back into the module

  • @rafaeltrovamala5787
    @rafaeltrovamala5787 7 років тому

    great video!
    I have arduino 1.8.3 and had the callback error, dont really understand why. but I used the code frome Jose Rivas provided in this comments, and works fine.
    Thanks to ItKindaWorks for the effort!

  • @derrickphon7322
    @derrickphon7322 4 роки тому

    Clean build

  • @dotmatrix2002
    @dotmatrix2002 8 років тому

    I get: "'callback' was not declared in this scope". When I add "void callback(char* topic, byte* payload, unsigned int length);" it gives an error: "connect_spec.cpp:2:24: fatal error: ShimClient.h: No such file or directory
    #include "ShimClient.h""
    Can someone please help me understand whats going on?

    • @dotmatrix2002
      @dotmatrix2002 8 років тому +1

      Further down the comments I read that Ide 1.6.5 works better. I use Ide 1.6.9. Changed to 1.6.5 and itkindworks. (No pun) :) Above problems disappeared and it assembled without hick-ups. It works. Thanks a lot for explaining this.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому +1

      glad you got it all working! I'm not sure about 1.6.9 but I know that using that declaration workaround should work at up to 1.6.8 (at least it does for me). But 1.6.5 is also my fallback and other than a couple features, most builds of 1.6.x seem mostly the same to me.

  • @IrfanAli-sf7wj
    @IrfanAli-sf7wj 7 років тому

    As you know private ip address is not a static address. It changes. MQTT client connect to raspberry pi using ip address of broker. so how to overcome this issue.

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      It should be easy enough to setup static IP addresses on your router. I would look up your router and see if you can set up a static IP for the broker. That is really going to be the only way to guarantee that you can maintain a connection to the broker.

  • @ankurpatel7455
    @ankurpatel7455 7 років тому

    not able to connect to mqtt... showing mqtt connection: failed

  • @Relentless_lel
    @Relentless_lel 7 років тому

    would this also be possible via a wlan hotspot on the pi? i dont want the system to be connected to the wlan router at home. or use it when there is no internet available.

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      It should be possible with any network as long as the ESP can connect to it.

    • @Relentless_lel
      @Relentless_lel 7 років тому

      yeah i'm trying to make my pi into a hotspot right now, which is more of a struggle than i thought.

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      did you get it working with the pi hotspot? I don't know if I have ever successfully created a hotspot on a pi (to be fair I think I only ever tried once a few years ago so I'm not the best resource there)

    • @Relentless_lel
      @Relentless_lel 7 років тому

      yeah it works now. i get the data from the esp when i subscribe to it on the pi. just as i imagined it to work. will go through your other vids now to complete my project :)
      thx for your video. they have been a great help already!!

    • @Relentless_lel
      @Relentless_lel 7 років тому

      do you have expirience with sending a struct via mqtt?

  • @ciremusyoka
    @ciremusyoka 6 років тому

    am thinking of creating my own custom app. is it possible to subsribe to the adafruit feeds from the app?

    • @ItKindaWorks
      @ItKindaWorks  6 років тому

      Yup, this should get you started! ua-cam.com/video/HUpwOQ7vL74/v-deo.html

  • @teddyruxpin3811
    @teddyruxpin3811 2 роки тому

    But why are you connecting to mqtt without a username and password?

  • @marinehm
    @marinehm 7 років тому

    at line : apt-get install mosquitto, I get an error
    could not open lock files, unable to lock administration directory.
    Help please...

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      Try looking at some of the solutions here www.tecmint.com/fix-unable-to-lock-the-administration-directory-var-lib-dpkg-lock/

    • @pfar94-j3u
      @pfar94-j3u 7 років тому

      add sudo in the front. "sudo apt-get install mosquitto". sudo gives you admin rights

  • @robsondias258
    @robsondias258 8 років тому

    can you plz help me I'm having some problems, when I go to compile I get an error i have the PubSubClient and ESP8266WiFi installed
    mqtt_esp8266:25: error: 'callback' was not declared in this scope
    PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
    ^
    exit status 1
    'callback' was not declared in this scope

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +Robson Dias what version of Arduino do you have installed? And do you have the pubsubclient library installed into your libraries folder inside of the sketch folder?

    • @robsondias258
      @robsondias258 8 років тому

      +ItKindaWorks Arduino IDE V1.6.9 and the pubsubclient library is in my library folder

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +Robson Dias Ok, I would roll back to 1.6.5 - the newer arduino versions aren't fully compatible with the ESP platform yet

  • @milanchhatralia3758
    @milanchhatralia3758 7 років тому

    Will it work over local network or can control over the internet?

    • @ItKindaWorks
      @ItKindaWorks  7 років тому

      It should work over both. You just have to specify the correct address for the ESP module to connect to.

  • @matthiasgehrmann1573
    @matthiasgehrmann1573 7 років тому

    great ! thank you for your detailed instructions :)

  • @chiranjeevisrinidhi2554
    @chiranjeevisrinidhi2554 6 років тому +1

    Hello every one iam new to the concept of MQTT. when i go though your videos found interesting and started following it. now when i kept hand on the job. i made MQTT broker ready. but when i try to upload client code in my ESP module it says below message:
    PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
    exit status 1
    'callback' was not declared in this scope
    I am using Arduino 1.8.5 which is latest one. is there any help to get rid of this error without downgrading my IDE.
    Thanks in advanced.

    • @top6062
      @top6062 6 років тому +1

      Chiranjeevi Srinidhi
      char* lightTopic = "/test/light1";
      // Callback function header
      void callback(char* topic, byte* payload, unsigned int length);
      WiFiClient wifiClient;
      PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);
      void setup() {

  • @harridarmawan4765
    @harridarmawan4765 8 років тому

    Hi ItKindaWorks,
    cools video you did there.. may i know what firmware of ESP you used? sorry for noob question, i am new here. :)

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      The firmware is custom generated from the Arduino sketch shown in this video. You can find links to the code in the description.

  • @uvatha3962
    @uvatha3962 8 років тому

    I am beginer, have pi3 and try to test publish mosquitto but it give an error
    mosquitto_pub -t "/test/topic" -m "HELLO"
    Error: Connection refused
    I don't understand why, i search on multiple forum and don't find this error report.
    i re-install mosquitto and same result.
    Do you know and have issue?
    Thanks

    • @GEISTIFT
      @GEISTIFT 8 років тому +1

      i completely removed and redid the whole process
      sudo apt-get --purge remove mosquitto mosquitto-clients python-mosquitto python3-mosquitto
      sudo apt-get purge --auto-remove mosquitto mosquitto-clients python-mosquitto python3-mosquitto
      sudo apt-get update
      and
      sudo reboot
      cos why not.
      then i followed the tutorial again from the beginning
      I also removed the keys and lists

    • @uvatha3962
      @uvatha3962 8 років тому +1

      LoLMaN thanks, i do it and now it work. Thanks again

    • @GEISTIFT
      @GEISTIFT 8 років тому

      Uvatha np dood

  • @dummydummy3388
    @dummydummy3388 7 років тому

    sir it is possible to turn off the led without human intervention??? for example the led will turn off after a couple of mins...any reply is greatly appreciated and thanks in advanced

    • @ItKindaWorks
      @ItKindaWorks  7 років тому +1

      You could always just modify the code to turn the LED off automatically. The most simple way to do this would be to change the code in the callback to look something like this:
      //turn the light on if the payload is '1' and publish to the MQTT server a confirmation message
      if(payload[0] == '1'){
      digitalWrite(lightPin, HIGH);
      client.publish("/test/confirm", "Light On");
      delay(30*1000) //delays for 30 seconds (change 30 to the number of seconds that you want to keep the light on for)
      digitalWrite(lightPin, LOW);
      }

    • @dummydummy3388
      @dummydummy3388 7 років тому

      thanks for the informative reply sir and have a good day

    • @dummydummy3388
      @dummydummy3388 7 років тому

      one more thing sir is it also possible to turn off an led by publishing a mqqt message based on a sensor??? for example proximity sensor

    • @ItKindaWorks
      @ItKindaWorks  7 років тому +1

      As long as the device doing the sensing can publish to MQTT, sure! :)

    • @dummydummy3388
      @dummydummy3388 7 років тому

      does the arduino code works on esp32???

  • @kekecjan
    @kekecjan 8 років тому

    Hey is it possible to control 2 LEDs or more with your code?

    • @Killernova86
      @Killernova86 8 років тому +2

      ofcourse this is possible but it will take some coding skills. But its rather easy !

    • @kekecjan
      @kekecjan 8 років тому +1

      i already done it was really easy.

    • @Killernova86
      @Killernova86 8 років тому +2

      Nice!

    • @awaisahmadsiddiqi6505
      @awaisahmadsiddiqi6505 8 років тому

      hints or keywords please

  • @zygimantasjasiunas5240
    @zygimantasjasiunas5240 5 років тому

    It says error: 'callback' was not declared in this scope

  • @octocat7949
    @octocat7949 8 років тому

    that was very detailed video, thanks =)

  • @DezeTimisTim
    @DezeTimisTim 8 років тому +1

    I use this exact code and include the same libraries that I have already installed. But when I compile everytime the code says "client" (for example in "PubSubClient client(....", "if (!client.connected()...." or "client.publish(...."), I get an error that says 'client' was not declared in this scope. Does anyone have ideas on how to solve this? I can't figure it out :((((

    • @kekecjan
      @kekecjan 8 років тому

      Have you used Arduino 1.6.5, i got also same error if i had latest version.

    • @DezeTimisTim
      @DezeTimisTim 8 років тому +2

      I actually use 1.6.7. But I fortunately solved the problem by adding so called prototypes to the beginning of the code. Here is what I did extactly:
      In between line 17 (const int lightpin = 2;)
      and line 19 (char* lightTopic = "/test/light1";), I added the following lines of code:
      void callback(char* topic, byte* payload, unsigned int length);
      void reconnect();
      String macToStr(const uint8_t* mac);
      unsigned long currentMillis = 0;
      This way the compiler knows "not to worry" because these functions will be coded later, below the loop :)
      I hope this will help you! Let me know!!

    • @kekecjan
      @kekecjan 8 років тому

      OK i understand. have you ever tried with 2 LED i am intresting with that. How can i make the code to control 2 LEDs or realay.

    • @DezeTimisTim
      @DezeTimisTim 8 років тому

      Below line 17(const int lightpin = 2;) you van add another line: const in lightpin2 = x; with x being the gpio you want to use. And you can type any name instead of "lightpin2". And of course you have to add digitalWrite(lightpin2, HIGH/LOW) wherever you want to turn it on or off

    • @kekecjan
      @kekecjan 8 років тому

      but if i do that the both LEDs will light up do i need also change in payload or somewhere else.

  • @thechriskelly12
    @thechriskelly12 8 років тому

    I have pub sub installed it says
    'callback' was not declared in this scope

    • @snoopymartin
      @snoopymartin 8 років тому

      i got the same error?

    • @thechriskelly12
      @thechriskelly12 8 років тому +1

      Martin Udo I installed arduino 1.6.5 and it worked

    • @SeniorLifeDeveloper
      @SeniorLifeDeveloper 8 років тому

      your advice helped me :)

    • @ulf8468
      @ulf8468 8 років тому

      same error with arduino 1.6.12. any solution?

    • @thechriskelly12
      @thechriskelly12 8 років тому

      as I said install Arduino 1.6.5 not 1.6.12 then try.

  • @arhitektche
    @arhitektche 7 років тому

    Amazing tutorial!

  • @ZulfiqarAadil
    @ZulfiqarAadil 7 років тому

    Why not use uMQTT broker inside of ESP accept PI or online MQTT brokers

    • @ItKindaWorks
      @ItKindaWorks  7 років тому +1

      As far as I know no one has had any real success setting up an mqtt broker running on an ESP. They just dont have the memory or bandwidth to handle the job. As for a cloud based broker, it's certainly an option but I personally would rather not send sensitive information about my home to some website that I only trust because it has a nice home page.

  • @BAMFWrangler
    @BAMFWrangler 7 років тому

    What watch are you wearing? Thanks

  • @AmirAli-yk4xb
    @AmirAli-yk4xb 7 років тому

    Nice Video: Just one question I am using username and password on my MQTT so the change would be
    PubSubClient client(MQTT_SERVER, 1883, , , callback, wifiClient);can you please confirm.thanksUTASS

  • @rushic24
    @rushic24 8 років тому

    I dont know how to use that github code because its given #include esp8266.h ,anyways i wrote this code it is not connecting to wifi automatically , i need to type those at commands at start ,how to do this fully automatic ? i want to make it work without pc.
    #include
    #include
    SoftwareSerial mySerial(2,3); // RX, TX
    void setup()
    {
    pinMode(9,OUTPUT);
    delay(10);
    Serial.begin(9600);
    delay(10);
    mySerial.begin(115200);
    delay(1000);
    while(mySerial.available())
    {
    mySerial.println('AT+CWMODE=1');
    delay(1000);
    mySerial.println('AT+CWLAP');
    delay(1000);
    mySerial.println('AT+CIPMUX=1');
    delay(1000);
    mySerial.println('AT+CWJAP="Swaraj_WLAN","internet"');
    delay(1000);
    mySerial.println('AT+CIPSERVER=1,4444');
    delay(1000);
    mySerial.println('AT+CIFSR');
    }
    }
    void loop()
    {
    if (mySerial.available())
    {
    String a;
    a=mySerial.readString();
    Serial.println(a);
    char b[15];
    a.toCharArray(b,15);
    Serial.println(b[9]);
    if(b[11]=='o'&&b[12]=='n')
    {
    Serial.print("This segment ram!");
    mySerial.println("ligt of");
    mySerial.write("light switched off");
    pinMode(9,OUTPUT);
    digitalWrite(9,HIGH);
    }
    if(b[11]=='o'&&b[12]=='f'&&b[13]=='f')
    {
    Serial.print("This 2 segment ram!");
    digitalWrite(9,LOW);
    }
    }
    if(Serial.available())
    {
    mySerial.write(Serial.read());
    }
    }

  • @arduwin7753
    @arduwin7753 8 років тому

    thanks for this vid! it´s great for a mqtt beginner like me. i want to read out a canbus device with my raspberry (socketcan). i also want the raspberry to be a mqtt broker. is this possible? the raspberry would be broker and client at the same time. i want to subscripe with my pc to raspberry than and read out the canbus messages.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      +ArduWin Glad to help! It's totally possible! All you need to do is make sure you have a broker installed (like mosquitto) on your raspi and then use an mqtt client for your CAN communication in whatever language your working with.

  • @sunitapatil381
    @sunitapatil381 5 років тому

    explination was ossum

  • @saif91565
    @saif91565 8 років тому

    Awesome Tutorial i liked it very much :D any tutorial so that we can communicate with our own webpage ?

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      In what way do you want to communicate with a webpage? I know it's not too hard to get an ESP to do GET and POST commands to a specific page.

  • @nicoisconfusion
    @nicoisconfusion 8 років тому

    Im having a bit of an issue. I have used your ESP8266_SimpleMQTT.ino file and changed the SSID and password to match. I am using a NodeMCU1 and have selected the NodeMCU1-ESP12E board. The Code appears to upload fine and will manually turn the light on and off through the relay when the sketch finishes uploading.
    So it appears everything is uploaded however it appears that it is not actually on the network. If i check my router I can see the devices that are connected and there are only my standard iOS devices and nothing that would appear to be the ESP. I tried on a hidden SSID first and then on the public SSID but I get the same result.
    Any ideas on what might be happening?
    This is what arduino IDE shows me
    Sketch uses 231,817 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
    Global variables use 32,288 bytes (39%) of dynamic memory, leaving 49,632 bytes for local variables. Maximum is 81,920 bytes.
    Uploading 235968 bytes from /var/folders/tf/h1lrg0kj0n74_dc6wc4567yr0000gp/T/build1782850646776807593.tmp/RelayLight.cpp.bin to flash at 0x00000000
    ................................................................................ [ 34% ]
    ................................................................................ [ 69% ]
    ....................................................................... [ 100% ]
    When i view the board monitor with the sketch i don't see any information getting printed out about the wifi connection or if it is reconnecting or anything. only
    ets Jan 8 2013,rst cause:4, boot mode:(1,6)
    wdt reset
    If i use the ESP8266 example sketch WiFiClientBasic and put in the SSID and password I can see it print out information about it connecting to the network and what its IP address is. I can ping that address. If i go to my router I can also See the device named ESP_869B97 connected with the IP address from the printout.

    • @ItKindaWorks
      @ItKindaWorks  8 років тому

      Hmm thats odd. Are you sure that you have the SSID and password in correctly - it is case sensitive. Also can you upload just the normal arduino blink (modifying the ledPin to match one on the NodeMCU) and confirm that uploads are indeed working? Also maybe try removing the MQTT parts of the code and see if you can just get it to connect with an empty loop (except for a delay) and no MQTT - I can't remember but it might be possible that if the MQTT broker isn't up and running it might reset the ESP when it tries to connect.

    • @nicoisconfusion
      @nicoisconfusion 8 років тому

      Yeah i have the correct SSID and password. If i used the WifiClientBasic example and replace the SSID and PW in there it connects up and gets an IP address that i can then ping
      This is what the serial monitor looks like.
      Wait for WiFi... .....
      WiFi connected
      IP address:
      10.1.1.238
      connecting to 10.1.1.1
      closing connection
      I have gone back and grabbed a copy of your LightNode.ino from Github rather than the RelayLight.ino and it uploads and actually connects to the network now
      Connecting to SSID-Name
      .......
      WiFi connected
      IP address:
      10.1.1.238
      Attempting MQTT connection... MTQQ Connected.
      I then plugged in 3.3v to the VIN on the Relay, GND to GND and GPIO9 to IN on the relay. Updated the pin to pin 9 in the sketch and uploaded again only to get the same errors as last night
      ets Jan 8 2013,rst cause:4, boot mode:(1,4)
      wdt reset
      I tried unplugging everything from the ESP and every time i upload the sketch again i just get that same error. I changed the PIN back to pin 2 as it originally was and it now uploads and connects again. I had it in SD2 which the wiring diagram said was GPIO9. It would not allow me to call it SD2 in the sketches it said SD2 was not declared in the sketch.
      I Changed over to D2 uploaded the sketch again and It is all working. The last issue that i am having now is that the status in home kit is the opposite to the actual lamp status. If it says off in home kit it is actually on. HAP sets the state to 1 and the light turns off which appears to be the opposite of. I have the power cable for my lamp running into the COM terminal and NO terminal on the relay
      //turn the light on if the payload is '1' and publish to the confirmation topic so the python script can log it
      if(payload[0] == '1'){
      digitalWrite(lightPin, HIGH);
      client.publish(lightConfirmTopic, "On");
      }
      //turn the light off if the payload is '0' and publish to the confirmation topic so the python script can log it
      else if (payload[0] == '0'){
      digitalWrite(lightPin, LOW);
      client.publish(lightConfirmTopic, "Off");
      }
      I have the power cable for my lamp running into the COM terminal and NO terminal on the relay

    • @nicoisconfusion
      @nicoisconfusion 8 років тому

      Changed the cable from Normally open on the relay to Normally Closed and it now works as expected.

  • @easwaran83
    @easwaran83 5 років тому

    great video awesome. Am curious to know where I can enter my MQTT server username 7 password. I see only entering IP address of MQTT server, please help