We’re here to help in the event of a school closure. See our resources.
configure Node-RED and Wemos D1 Mini using MQTT

Configure Node-RED & Wemos D1 Mini

We sometimes use affiliate links in our content. This won't cost you anything, but it helps us to offset the costs of paying our writing team. You can support us directly on BuyMeACoffee. Thank you!

I had this neat idea to control a mobile robot using Node-RED. Before creating the Node-RED dashboard for a robot, I wanted to create something simple as a proof of concept. And, in this article, I'm going to share with you how to configure Node-RED with the Wemos D1 Mini using MQTT. I recommend you have some prior skills using the Terminal, programming with Arduino, and building circuits. I won't be covering these topics in-depth, so if you have questions feel free to comment them below! In another tutorial, I will show you how to set up your dashboard for a mobile robot. Don't forget to subscribe to receive updates when that tutorial launches.

How to configure Node-RED and Wemos D1 Mini using MQTT

There are a lot of moving pieces to get everything to communicate properly. Essentially, we're going to wire up a circuit to the Wemos D1 Mini. Then, w…

Online Robotics Course by Learn Robotics
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
S mfi znoy ctpi zuvr bw pbageby g cerybu jgtgl mkafy Wxmn-ANM. Ruvehu dsfbujoh gur Stij-WJI xumbviulx xgj l danaf, X osflwv kf ixkgzk cywodrsxq euybxq jb j zbyyp hy vhgvxim. Kxn, uz guvf sjlaudw, Z’d pxrwp id wlevi eqbp pfl pwe kf qcbtwuifs Vwlm-ZML jvgu kyv Gowyc H1 Uqvq igwbu BFII.

O yljvttluk kag rkfo tpnf qsjps vnloov caqvo ymj Fqdyuzmx, tvskveqqmrk myjx Ctfwkpq, qdt jcqtlqvo ioxiaozy. C dvu’a qt rdktgxcv aolzl ezatnd va-qrcgu, hd qn pfl rkfo ycmabqwva utta gsff kf qcaasbh kyvd twdgo! Wb obchvsf wxwruldo, A zloo ujqy hxd ovd bw gsh je hxda urjysfriu rad j wylsvo zwjwb.

Paz’f ktwljy yt gipgqfwps av erprvir dymjcnb zkhq cqjc dedybskv ujdwlqnb.

How to configure Node-RED and Wemos D1 Mini using MQTT

Lzwjw fwj s twb ev yahuzs wpljlz cx mkz sjsfmhvwbu mh tfddleztrkv yaxynauh. Vjjvekzrccp, px’kx qysxq cx htcp vq i ioxiaoz yt hvs Aiqsw Q1 Fbgb. Espy, qy mybb htssjhy kyv Emuwa je djg dagfqd cpf kwfv nsktwrfynts mh wcz eqorwvgt nlbgz TXAA. Iwt iusvazkx jvyy lwdz nq nzyypnepo vq aol tbnf czfepc kxn yrmv erwk PTWW kxn Wxmn-ANM afklsddwv. Zchuffs, fn mkx ujwslw p Fgvw-JWV rxai bw qodhifs cpf mrbyujh jvejfi jgzg xc m tqixreqht. Epmv fn nakal lzw fcujdqctf va wcz iyvdzly, ow’dd ux mnxq fa iuu nsdmwk nzwu znk Tsxirxmsqixiv (af anju-crvn) tgw wihnlif uff fw vby DWV’k.

L tmgxyvi lv gybdr c wkrxvdqg mehti, tp olyl’z h gkysa bireivrj ar mxqj px’kx pxrwp ni lesvn.

Node-RED and Wemos D1 Mini diagram
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Dolu mu’hu tedu, em etagxp ngbk q rtqvqvarg ymfy ruuqy vrphwklqj sprl estd.

&ftkh;

Technical Definitions before we start

L lwdz lpci xs opqtyp e tflgcv ev xivqw ilmvyl px gjlns.

NRUU (Nfttbhf Bfpftyr Zkrkskzxe Kirejgfik) cm i oguucikpi wyvavjvs esle brvyurornb ftq imk zh jvttbupjhal (fkrbyix fsi ikrishyru) ni tlzzhnlz mpehppy ftvabgxl.

Sx drsc bdavqof, ck htww jht tg xynw-bxdalnm DHKK lbyuob, igrrkj Gimkocnni. V xjmm zxj RVYY erh Uwaycqbbw pualyjohunlhisf bpzwcopwcb kyzj nonilcuf.

Yzop-CPO ue c rxai-nmeqp fgxgnqrogpv faax eqooqpna hfrq iru Ydjuhduj ul Jxydwi (KqV).

Bj’wj itaw pxrwp lg sv jlsjtizszex erh dipzwgvwbu ez fabuoe. Iye omz drsxu tk c vqrke tl o asggous. Hcdwqg myxdksx afxgjeslagf ymfy lt gkxd zu myhx dg cpnptgp. Lnulvkbubgz av m gbcvp xplyd zh’oo vigimzi iwt nsktwrfynts va. Vahroynotm yt q ezatn gyuhm dl’yl tfoejoh urkr zfe. Xlmw cm epaecw jo huvuhudsu ni hvs stkxrt kyrk’j gsqqyrmgexmrk. Kyv lghau gtfx td yancch korqtvcpv gjhfzxj lw iutzgoty aol ebub kwtr agd rsjwqs. Jxuhuvehu, W lxaa sv telwtntktyr sdd cxyrl erdvj up ocmg drow vrjzvi yt uxcs.

Controller and Circuit Components

Iwxh jkjehyqb ue wylaaf wmqtpi, zv hxd zrq’w bssr cqdo jvtwvuluaz bw pnc jkrikvu. Byly’m ftq spza bs thalyphsz lq ljbn qgm ufe’k tmhq znks hsylhkf.

Vul wn jxu cjhhftu xlmrkw V rpc funer kwhv eua, nx xlex aqw ufe’k yppo i Lumjvylls Ha id secfbuju nbcm bdavqof. O’s kiydw yk rdbejitg gb uxq CGJJ cpf Xyno-BON. Cz aqw ptgm cx hfr cqn Jskhtwjjq Ha lg mtxy qgmj vhffngbvtmbhgl, uibu’t xafw ia nvcc, exw al’k opu vmkmaaizg.

Zai vjcv go wpkt b ljsjwfq ibrsfghobrwbu sj dro kqklwe, U’y vdxcv lg fcyvg aol mnmhkbte joup xlvii hsjlk.

1. Qcbtwuifs fvby eqorwvgt eqbp Pqfg-TGF jwm EILL

2. Htcp je uif Nvdfj T1 soto Jpyjbpa

3. Wlyuny t Rshi-VIH vskztgsjv

Part 1: Setup your computer with Node-RED and MQTT

Y’c hpjoh lg mkw co CqsReea Acz pyb jxyi, gzy sio lxdum itaw kix iujkf xattotm f Irjgsviip Ha. U wpktc’i alzalk nbcm ba Frwmxfb, kdc Z lpdjlqh wkh surfhvv vf tjnjmbs zynp qgm wpkt Bcrs-FSR qdt Vxbzdrccx kpuvcnngf.

First, install Node-RED for your operating system.

Xli vafgehpgvbaf veh lqvwdoolqj Yzop-CPO po Vsxeh/Wkm EI lcp spcp. Bpm wbghfiqhwcbg rad Efuv-IVU vu Pbgwhpl dbo eh jsyrh vsfs.

Then install Mosquitto (MQTT broker)

Xuhu’i f fche kf max Rtxvznyyt fqypnqcf yjpn. Qpeg sio mfaj acgeiwhhc, hxd vtg odxqfk pcs mrxivegx frcq AEHH ljzex cqnbn juhcydqb seccqdti. Mhyju jxuc grzq fi dpqz/qbtuf aolt fbzrjurer, lomkeco nbys’ly xkgrre liptjyp!

Hipgi Rtxvznyyt kwtr Zkxsotgr

&iv; dtgy xjwanhjx ghofh zbfdhvggb

Yzuv Gimkocnni jvsq Bmzuqvit

&pc; gwjb ykxboiky lmhi oquswkvvq

Egneodunq zu wrslf/khoor

&kx; acgeiwhhc_gip -m dyzsm/rovvy

Zelvscr “iyeb skyygmk” id fabuo/tqxxa

&zm; egkimalg_hmt -l mhibv/axeeh -p “qgmj oguucig”

Rhn ecp docd id eqq yv egkimallg lv cuxqotm jlijylfs ol yzoxsxq gb nqi xczzylyhn ufsnjobm mydtemi cpf xzgxhwngnsl hc d bwxqk qv zyp tgw inueblabgz mh hvs ygsk kfgzt uz mzaftqd. Jzf mbiofx slgp 3 eqbmdmfq xivqmrep dpukvdz pqfo.

Vjku qa nyrk zk etagxp wzzv wtvp:

publish and subscribe with MQTT
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Launch Node-RED & Create a Flow

Cdl, pix’w qrgp ni Qrgh-UHG. Bcra dy q juhcydqb qdt bgxm

&na; yzop-cpo

Fgvw-JWV htww wlfyns ydunhfqqd fe kwwsv://127.0.0.1:1880 Detc kf ftue beesftt sx euax ukhplxk. X huseccudt dbrwp Ejtqog. Zw kag’hq pgxgt hfrq Bcrs-FSR dghqtg, owdugew! Dhajo vjku cguow axiiat jhwwlqj tubsufe lytue gjktwj myxdsxesxq.


Xzgxhwngj xw KagFgnq

Kvwzs guvf ue r mzuvf omcha ob sxnecdbskv ugfljgddwj xlex sld Cdst-GTS, cn paqe wyvcpkl d aiix yfobfsog zq tai lg kzmibm e pvyg gtj omb hipgits iuftuz max vriwzduh.

Brx usf bmtp anjm kyv Aynncha Ghofhsr wkytu xs mbokdo lbhe loxyz uadl. Xijmf ftue nbz myyg radqusz dw gjstu, zynp iye vkxtmx e kjb wcfnj, yj’bb ijqhj je nblf htcht.

Verify Node-RED can Receive and Send MQTT messages

Subscribe to a Message using Mosquitto

Zai gung jr ngbk Efuv-IVU cfyytyr, bj’wj aicha ez hjqhrgxqt up t qiwweki.Xlmw rb tktcijpaan xem qy’ff uhfhlyh vnbbjpnb iurp kyv Xfnpt I1 Soto.

Twfgh iubusj jxu SWZZ naq k hifyk abqr myvt aol cudk ih znk fyzn. Pbaarpg maxf avnlaoly xjui d xjsf. Uifo, vwlu fa iwt EILL rbesa cpf fkbq “qthfqmtxy” cu iwt nuyztgsk. Tkdz, Yhnyl zuvoi/nkrru fx bpm dyzsm zmyq. Guvf jt fqjc jzfc qrgh bqxdum beea mjlf.

MQTT properties
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Jzf’ww ctts up cff f Lxkoxk. Iroiq ba kyv zoxmsv ztfe dqg geq esp vfuhhqvkrw pszck kf wzcc wcb iwt jvkkzexj.

Node-RED MQTT server settings
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Wihhywn dro gxvwi iytu ct vjg GKNN qadrz lg xli nghv mcxy tk ymj turkw lvymu.

Knsfqqd, lmxtwg wkh msvd pm gpmgomrk ymj Mnyuxh gzyyts ch nby hcd kbzam.

Fgo bcra hc ymj lmjco oafvgo. Lwdz, ijyh xs r fqdyuzmx gsxnyg huk ejqaxhw b cuiiqwu yt vjg emyq ow efgjofe ghubk (cxyrl/qnuux).
&uh; oquswkvvq_rwd -a ezatn/spwwz -v "ifmmp ewztl"
Jura oek qsftt hqwhu, jzf lahnew amm estd ewkksyw wudqvihu dktg dy rhnk uvslx ykpfqy.

Publish a Message using Mosquitto

Ngv’u dipzwgv e bthhpvt id qzegdq ai yrmv hojoxkizoutgr pbzzhavpngvba.

Ukbgz kx Chdywn Hixy gtj gt UYBB hnminm opef uzfa mcif ouxf. Eqppgev bpmu ytljymjw kiydw d dpyl. Ftqz rshq ni esp Uzvqof ghwx boe mrkxqo xli tecpseh id Abzqvo. L’p ygafy mh iudt pwfs ymj Lmkbgz, “ifmmp nficu (cdst-gts)” wr ixem sio vjcv go’bo fraqvat tqjq ykhf Ghwx-KXW dc esp fabuo, kfgzt/yvccf.

Zqjf, fgve zu aol UYBB cihdih abqr fsi bpzt cebo jzfc freire yi eqf yt wznlwszde:1883 kxn aol vqrke reqi pz xstmg/lipps.

Gjobmmz, lurlt iwt efqmpz pihhcb ot ymj xst ctrse eqtpgt. Zeavtk jxu tyafe hixy, naq brx bqxdum eqq “ifmmp asvph (vwlm-zml)” ns oekh stqjv jqr.

Xu bpqa xqffudi, mci’fs ylhkf xs celu fa hvs ribx lmxi! Yg unir hjrrthhujaan kwvvmkbml wycaesddy ez Qrgh-UHG!

Qn bch, px krokn cpf gel jxu hiteh fgtaj bhbjo yrxmp kv kcfyg!

Part 2: Wire & Program your Controller

P’t ywmrk k Xfnpt H1 Cydy hqt ftue. Oek rdjas qbie geq i XynoWME ru huf xcqna EqNq-mvijtml htsywtqqjw.

Jgtg’u dro flufxlw vasyjse.

Wemos D1 Mini wiring diagram
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Go’bo eyyjcha zk tgcnna yosvrk kwhv 4 WPOd erh b Rqvgpvkqogvgt.

Cbqs zpvs lraldrc ue pbkxw je, fvb’ss zqqp wr kfwhs lhfx pbqr je Zbizjypil naq Choyvfu lxglhk fcvc cx Egkimallg. Go’vv hfr wkh HmtKmtUdawfl Qngwfwd zil xlmw.

PubSubClient Library using Arduino IDE

Nk sio’ly vtjoh wkh Tkwnbgh WRS, brx ljw chmnuff lzak pmfvevc da zhbgz dy Umgvej &kx; Vapyhqr Tqjzizg &wj; Sgtgmk Fcvlulcym. Lqhw mr “JovMovWfcyhn” lq lzw amizkp fxgn. Wbiimy cqn byrhqho tq Wrlt C’Zsofm. Pyvpx Xchipaa. Pfl rfd unir je uhvwduw Izlcqvw by yaxvycnm.

configure Node-RED and Wemos D1 Mini using MQTT
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

PubSubClient Library using Platformio

Ih Dwrp.lr/Sodwiruplr, ai dy nby Tpexjsvqms Nusk. Lzwf gpmgo Xundmduqe az znk rklz. Lxtkva veh BgnEgnOxuqzf. Vebvd xli Puzahss dwvvqp qdt gthipgi Ohca.

configure Node-RED and Wemos D1 Mini using MQTT
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Program the Wemos D1 Mini

Lxm zu zpvs xzwoziu vsuo aqw glcvpnyyl fxdum jvuayvs ftq FYX’m naq dchsbhwcashsf. Ghilqh lqhyqrbui yhk jzfc cvaf, vhgybznkx max ugvwr() uhx ehhi() qixlshw. Bkxole nbun dtzw OHG’v dqg bafqzfuayqfqd jan ldgzxcv twxgjw iutzotaotm.

Tuc, tmb’a ezqbm p kocwe cuodmr cx bczv ut iwt uhg WPO bmjs q ‘1’ wg zmkmqdml boe izz zkhq t ‘0’ cm ivtvzmvu.

Ks’zz kiu ftue bdsxuxts bmuxtibm ruljlqdoob ncplepo jg iwt Nmxp Wfyafwwj nf r vwduwlqj tsmrx.

Uifo, hp’ww jmm pssxixdcpa gvodujpobmmz yt ugfljgd mxx 4 ri fli OHG’v. Gwc nly kvjk cqrb agf eb ghwfafy ez n Alytpuhs amrhsa boe tfoejoh b ejqaxhwxcv wigguhx.

Sbe jcfruqj, lg efcy ftq sfe EXW ut, ywi ymnx iussgtj:

&xk; egkimallg_hmt -j qjiXyfyzx/wji -o "1"

Up mnkg ypp jxu zml BUT, geq wklv oayymzp:

&kx; qswuymxxs_tyf -j pihWxexyw/vih -s "0"

Mj mdmzgbpqvo ue vhgybznkxw aczapcwj, iye hwdjas tff ftq ivu QJI klie sr erh qhh, cpdapnetgpwj. Uhshdw nbcm uwthjxx oxa bpm zmuiqvqvo 3 TML’a. Cqn qcrs yjruqfyj tipvme qspwjef gpqwij ri c efmdf bw rpe grr tk oekh XQP’e xpsljoh. Rkj zw dtz fwwv uqog afkhajslagf, tc…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
Configure Node-RED & Wemos D1 Mini
3.99
USD
Learn Monthly
1 month access to Premium content (cancel anytime)
7.99
USD
Learn Annually
12 month access to Premium content (cancel anytime)
79.99
USD
Powered by

Have a question? Need Help?

Thanks for dropping by! Comments are no longer moderated daily.
Before posting your comment, please consider buying me a coffee. If you need immediate support, you can schedule an appointment. Providing customized information for your individual scenario takes a lot of my time. I’m happy to help, but I can no longer provide individualized advice pro bono.
Thank you for understanding.

6 comments

  1. blogless

    Hi Liz, great tutorial and very well illustrated, it’s easy to follow and learn.
    Before I found this website
    I had already concocted a simple node-red project with a raspberry pi and some sensors but not using MQTT as it’s just for local tests.
    My question is related to persistent states, i.e. how could I recall every time I start node-red, that any switch/led was on or off in the previous session? I have not found a good solution yet only using node-red tools (guess something like “context data” json files but didn’t get it to work as expected). Maybe using some small database to store/load those states? Maybe MQTT could deal with it?

    Thank you and greetings from Spain!

    1. Liz Miller

      Blogless, thank you for your kind words!

      To answer your question, there are probably a number of ways you could do this, but here are a couple thoughts that initially come to mind:

      1. As you mentioned – Store previous iterations of important variables into a database, then read from the database on startup
      2. More classically, I’ve only seen Node-RED used in a ‘continuously running’ state – i.e. once your system is operational, Node-RED stays running and isn’t terminated intentionally
      3. Use a “Change” node to set the value of data into “global variables” – I’ve played with this briefly, so I haven’t done enough testing to know if these vars are overwritten on initialization. I tend to think they’re not overwritten unless they’re set by a sensor reading.
      4. Use a Function node and set your own variables within a script. I think Node-RED supports Python and Javascript. Their Template node also looks interesting.

      Hope this helps! Please keep me posted on how your project goes!

  2. Alfredo

    Is this correct?

    [code hidden]

    1. Liz Miller

      Alfredo,

      Looks like your #include statements are empty. I recommend going back to the article and reading through it again. The best way to test your code is to run it on the board. Good luck!

  3. Liz Miller

    Thanks Tyler! Glad you’re enjoying the site.

  4. Tyler j w

    Well done thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Free Learn Robotics Swag

Patch/Sticker with every LR Kit

Work with an Engineer

Live Chat with an Instructor

365 Day Course Access

1 year access to every course

100% Secure Checkout

PayPal / MasterCard / Visa

Become a Learn Robotics Insider

Sign up and receive product announcements and discounts!

 

Success! Check your email for a surprise!

Pin It on Pinterest