-->
Page 1 of 1

NodeMCU ESP-12e Multitasking

PostPosted: Sun Oct 30, 2016 11:32 pm
by Proy
Hello all together,

I'm pretty new to the IOT/Arduino/ESP world and trying to play around with it for a couple of weeks.
In the meanwhile I got some things working already - however I'm a bit overwhelmed now.

Here's what I try to do:
I have a NodeMCU ESP-12e dev board and use Arduino IDE to program it. So far I used the modules to read temperature sensor data and publish it via mqtt to my raspberry pi. also I used my raspberry pi to send mqtt messages to the ESP-12e board to turn on/off leds. that worked fine.

For a current project I need the time, a LED matrix and MQTT. I want to display the time on a self made NeoPixel LED strip matrix and simultaneously listen send temperature data via MQTT and listen to MQTT for color changes/ mode changes and so on.
The single pieces are working more or less. - the clock is doing it's thing and MQTT is doing it's thing - however when I put it together MQTT is reacting really slow, sometimes missing incoming messages.

Code: Select all#include <ESP8266WiFi.h> //WiFi
#include <PubSubClient.h>
#include <DHT.h> //Temperature Sensor
#include <Adafruit_NeoPixel.h> //LEDs
#include <TimeLib.h> //Time
#include <WiFiUdp.h> //Synchronize Time


Code: Select allvoid loop() {
  // LOOP MQTT
    if (!client.connected()) {
      reconnect();
    }
   clock(); // --> Clock.ino
   client.loop();
  delay(10); //I did read somewhere a delay of 10 is positive here, tried 10, 100, 300,... nothing - It doens't seem to change anything
}


As you can see I'm calling all in the loop function. While further reading I found this about interrupts https://learn.adafruit.com/multi-taskin ... -interrupt is this the solution to my problems? to I have to change from every function within "loop" to something different?
Can I use the interrups from the tutorial with the ESP-12e? because I didn't get it to work.

I then found the #include <Ticker.h>. Is this "interrups" for ESP-12e?
I tried using it to call my clock function
Code: Select allflipper.attach(1, modeChanger);
But then I get a "stack" error in the serial monitor after 2 runs.

So long story short:
- Is my project oversized for the ESP-12e board?
- Are interrupts/ticker the solution to my problem (if used correctly)?

Thanks for any advice and tips

Re: NodeMCU ESP-12e Multitasking

PostPosted: Tue Nov 01, 2016 11:31 pm
by gdsports
I suggest using https://github.com/Makuna/NeoPixelBus instead of the Adafruit library. The Adafruit library disables interrupts to bit bang the WS281x LEDs. Disabling interrupts causes lots of problems for ESP8266 WiFi. NeoPixelBus can drive LEDs without disabling interrupts.

Re: NodeMCU ESP-12e Multitasking

PostPosted: Fri Nov 11, 2016 7:21 pm
by Proy
Thanks for that advice. it's working better now after changing the library