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/
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.
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!!
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!
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
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
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);
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
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
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
@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.
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.
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!
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.
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 ?
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.
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..
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
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?
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.
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.
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.
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...
+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.
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.
+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.
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.
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
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 ?
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.
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?
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..
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
+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
+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..
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!
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.. :)
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...!
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?
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?
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)
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!
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
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.
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?
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.
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?
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.
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
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?
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.
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/
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.
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?
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?
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
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!
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?
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.
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.
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.
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.
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.
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)
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!!
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
+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?
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.
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
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
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
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); }
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 :((((
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!!
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
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.
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
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()); } }
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.
+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.
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.
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.
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
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
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/
Where Can I Find Bounce2.h file
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.
Thanks!!
Nice video. You may also want to checkout the review of home automation on my blog at *bradleyreviews. com/home-automation-review/* Thanks, Dorian.
thank you
Still got this error. How to solve this ?
WOW!! It compiled!! God bless the Internet! Lets see if it works now...
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!!
EXCELLENT, very nice Clean code! Simple and straight forward explanation and demonstration of MQTT. I'm looking forward to the other videos!
Thank you so much! The only good tutorial i found on MQTT after hours of googling!
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!
This was one of my first videos... I've gotten a bit better with my newer videos :)
Great tutorial!!!! The best explanation about MQTT I've seen so far. Thanks!
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
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
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);
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
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
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
Very clear guide. I'm a beginner. Very happy when watch your video. Thank you very much!
+Chức Nguyễn You're welcome, glad you like it :)
Brilliant tutorial. Really explains end to end mqtt and esp8266. Thank you
Not tried it yet but this was a great intro to Pub/Sub using the ESP. Thanks!
Thank you for a great tutorial, I just got my ESP8266 module today and your tutorials were very handy.
@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.
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.
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!
Just spotted
Юрий Кушнырев post. Thank you, it was driving me mad :-) All working now.
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.
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 ?
Great video, simple and well presented. thank you
Thank you for posting this vid. Exactly what I needed to get started.
+Steven Bell Glad to help!
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.
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..
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
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?
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.
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.
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
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.
Thank you! You just made my weekend!!
The same sketch works on Arduino UNO + ESP8266 ESP-01? Normally I use SoftwareSerial.h to enable WiFi and other AT commands...!
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...
Great tutorial! Keep up the good work!!!
I'll have to look into MQTT. I'll be using I2C for the weather station.
+Fudmottin yeah mqtt is a great easy to use protocol
ItKindaWorks Did Apple by any chance adopt that for HomeKit? Or are they using a different standard?
+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.
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.
+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.
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.
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
here is the work around from GitHub github.com/ItKindaWorks/ESP8266/issues/7
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() {
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 ?
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.
Greetings from 2022. is this system still ok? can i still do it or changed a lot in that time? thx!
Thanks for this nice video... May I see the previous video? Of this
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?
have trouble with light code where i am getting an error in arduino compiling,
exit status 1
'callback' was not declared in this scope
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..
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
+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
+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..
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!
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.. :)
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...!
wHAT happens if you remove the delay() in the loop? My application does not like delay().
Good job ! Howe i can run this topic with Sonoff basic wi-fi relay?
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?
Amazing! Thanks for making this!
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?
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)
itkindaworks ... awesome job! ty so much!
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?
+geman220 I'll put it on my list of videos to make!
i cant understand how you place it on the breadboard? pins are shortcircuit?
Where is the short/where are you confused?
i am getting error like callback is not defined after defining also it is getting
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!
if your broker has username and pass, where do you add that in the code?
Could you give me some tips to improve the stability of the module?
a decent psu with maybe a 470uF over the chips powerlines?
Nice video. in the video esp8266 is not connected to arduino den how it is programmed.
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
Thank You. This video greatly helped me!
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.
Same problem dude. Is it solved?
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?
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.
Right, I'll check that out. Thanks! BTW, awesome channel. Keep on going :D
can we control thios throught internet from anywarein the word plz reply
How could this be modified to send a string message instead of a byte
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?
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.
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
here is the work around from GitHub github.com/ItKindaWorks/ESP8266/issues/7
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?
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.
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/
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.
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.
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?
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?
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
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!
Clean build
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?
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.
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.
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.
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.
not able to connect to mqtt... showing mqtt connection: failed
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.
It should be possible with any network as long as the ESP can connect to it.
yeah i'm trying to make my pi into a hotspot right now, which is more of a struggle than i thought.
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)
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!!
do you have expirience with sending a struct via mqtt?
am thinking of creating my own custom app. is it possible to subsribe to the adafruit feeds from the app?
Yup, this should get you started! ua-cam.com/video/HUpwOQ7vL74/v-deo.html
But why are you connecting to mqtt without a username and password?
at line : apt-get install mosquitto, I get an error
could not open lock files, unable to lock administration directory.
Help please...
Try looking at some of the solutions here www.tecmint.com/fix-unable-to-lock-the-administration-directory-var-lib-dpkg-lock/
add sudo in the front. "sudo apt-get install mosquitto". sudo gives you admin rights
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
+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?
+ItKindaWorks Arduino IDE V1.6.9 and the pubsubclient library is in my library folder
+Robson Dias Ok, I would roll back to 1.6.5 - the newer arduino versions aren't fully compatible with the ESP platform yet
Will it work over local network or can control over the internet?
It should work over both. You just have to specify the correct address for the ESP module to connect to.
great ! thank you for your detailed instructions :)
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.
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() {
Hi ItKindaWorks,
cools video you did there.. may i know what firmware of ESP you used? sorry for noob question, i am new here. :)
The firmware is custom generated from the Arduino sketch shown in this video. You can find links to the code in the description.
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
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
LoLMaN thanks, i do it and now it work. Thanks again
Uvatha np dood
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
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);
}
thanks for the informative reply sir and have a good day
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
As long as the device doing the sensing can publish to MQTT, sure! :)
does the arduino code works on esp32???
Hey is it possible to control 2 LEDs or more with your code?
ofcourse this is possible but it will take some coding skills. But its rather easy !
i already done it was really easy.
Nice!
hints or keywords please
It says error: 'callback' was not declared in this scope
that was very detailed video, thanks =)
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 :((((
Have you used Arduino 1.6.5, i got also same error if i had latest version.
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!!
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.
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
but if i do that the both LEDs will light up do i need also change in payload or somewhere else.
I have pub sub installed it says
'callback' was not declared in this scope
i got the same error?
Martin Udo I installed arduino 1.6.5 and it worked
your advice helped me :)
same error with arduino 1.6.12. any solution?
as I said install Arduino 1.6.5 not 1.6.12 then try.
Amazing tutorial!
Why not use uMQTT broker inside of ESP accept PI or online MQTT brokers
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.
What watch are you wearing? Thanks
It's a pebble steel
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
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());
}
}
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.
+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.
explination was ossum
Awesome Tutorial i liked it very much :D any tutorial so that we can communicate with our own webpage ?
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.
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.
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.
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
Changed the cable from Normally open on the relay to Normally Closed and it now works as expected.
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