-->
Page 1 of 1

Using WiFiManager and Thingspeak library crashes ESP-01

PostPosted: Mon Oct 17, 2016 4:45 am
by TiRe
Hi there,

I've implemented the WiFiManager and wanted to add a Thingspeak capability by using the library.
Compiling works fine but once uploaded, the ESP-01 chip goes into a reset after executing the write instruction (btw. same problem by running on NodeMCU 0.9)
Code: Select allThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);


Code and error message are shown below - any idea what is causing the problem??
(I've run several tests in this code hence some unused "code debris" are existing..)

I also tried to run without the WifiManager and initialized the Wifi on "conventional" way - then it worked without problems. So the reason seems to be linked to WifiManager in conjunction with Thinkspeak library?!


Code: Select all#include <Arduino.h>
#define DEBUGPRINT        // E/D Debug output
#define DEBUG_MODE

#include "config.h"

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>        //https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include "TMP100.h"
#include "ThingSpeak.h"




//String clientName;
//WiFiClient wifiClient;



// Temperaturesensor
TMP100 myTMP100(TMP100_ID); // create a instance of the sensor


ADC_MODE(ADC_VCC);

 float temperature; // this will hold the floating-point temperature

//float t = 0;
int vcc;

long startMills;


/* ================================================================================
 *          Setup
 * ================================================================================
 */
void setup(void)
{
  //ESP.eraseConfig();

  startMills = millis();
  // start serial port
  Serial.begin(BAUDRATE);

  //-------------------

  DBP();

  WiFiManager wifi;
  //wifi.resetSettings();
 
  wifi.setTimeout(120); //so if it restarts and router is not yet online, it keeps rebooting and retrying to connect

  if (!wifi.autoConnect("Temperatursensor")) {
    DBP("timeout - going to sleep");
    DBP(millis() - startMills);


    delay(1000);
  }


  //-------
 //setup hardware
WiFiClient myClient;


    //Wire.pins(int sda, int scl), etc
  Wire.pins(0, 2);                        //on ESP-01.
  Wire.begin();
  delay(20);

 #ifdef DEBUG_MODE
  DBP("Debug-Mode, fixed Temp used");
 #else
  myTMP100.init();  // initialize sensor
 #endif


delay(1000);
DBP("WiFi Client");
ThingSpeak.begin(myClient);
}

/* ================================================================================
 *            Main LOOP
 * ================================================================================
 */
void loop(void)
{

  vcc = ESP.getVcc();//readvdd33();
  // original loop
  DBP_("Supply: ");
  DBP((float)vcc/1000);
 

    // -----------------------------------------
     #ifdef DEBUG_MODE
      temperature=23.4;
     #else
      temperature = myTMP100.temperature();  //get temperature from the sensor
     #endif
   
    DBP_("Temperature: ");
    DBP(temperature);
   


   
    delay(10);
    sendData();

   
    DBP("DONE");

}





/* ================================================================================
 *  Sending data to the server
 * ================================================================================
 */
void sendData() {
 
    DBP("schreibe in Thingspeak ...");
    // ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
    ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
}



Error message is as follows:
Code: Select all*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.178.4
Debug-Mode, fixed Temp used
WiFi Client
Supply: 3.14
Temperature: 23.40
schreibe in Thingspeak ...

Exception (28):
epc1=0x402021f1 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000024 depc=0x00000000

ctx: cont
sp: 3fff0300 end: 3fff0590 offset: 01a0

>>>stack>>>
3fff04a0:  3ffe880c 00029eaf 3fff053c 3ffef564 
3fff04b0:  00000010 3fff0524 3fff0524 402090b4 
3fff04c0:  3fff14cc 0000000f 3fff0524 3ffef564 
3fff04d0:  3ffe880c 3fff0524 3ffef33c 402023e0 
3fff04e0:  3ffe880c 00029eaf 3fff0524 4020923c 
3fff04f0:  3ffe880c 00029eaf 41bb3333 40209264 
3fff0500:  3ffe880c 00029eaf 41bb3333 40202602 
3fff0510:  342e3332 30303030 00189f00 00000000 
3fff0520:  401059f8 3fff14b4 0000000f 0000000f 
3fff0530:  00000000 00000000 00000000 00000000 
3fff0540:  00000000 00000000 3fff14cc 0000000f 
3fff0550:  0000000f 3fff0e5c 0000000f 00000008 
3fff0560:  3fffdad0 3ffef2b0 3ffef4a8 402026e0 
3fff0570:  3fffdad0 00000000 3ffef55c 40209b18 
3fff0580:  feefeffe feefeffe 3ffef570 40100718 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3de0c112



Arduino-IDE: 1.6.12
Thingspeak library (by MathWorks) 1.2.1
WiFiManager 0.12.0
ESP-01 512k -> Generic ESP8266 Module selected

For sake of completeness the config.h as well
Code: Select all// TMP100
    const byte TMP100_ID = 0x48; // address of the first TMP100 0x48=144d
    //const byte TMP100_ID = 0x4A; // address of the first TMP100 0x4A=148d

// Baudrate für serielle Kommunikation
    const long BAUDRATE = 115200;



// Helpful for debugging
    #ifdef DEBUGPRINT
    #define DBP(x)  Serial.println (x)
    #define DBP_(x)  Serial.print (x)
    #else
    #define DBP(x)
    #define DBP_(x) 
    #endif


// Thingspeak
unsigned long myChannelNumber = 171695;
const char * myWriteAPIKey = "****************";

Re: Using WiFiManager and Thingspeak library crashes ESP-01

PostPosted: Mon Oct 24, 2016 11:36 am
by edwin
Crashes on a Wemos D1 as well. Have not used a Thingspeak library, just made connection myself, but ESP8266 keeps resetting. if I do just the WiFimanager example or on upload to Thingspeak no problem

Re: Using WiFiManager and Thingspeak library crashes ESP-01

PostPosted: Mon Nov 20, 2017 6:47 pm
by csambrook
I realise this issue is over a year old now but do you remember how it was resolved please?
I'm having a very similar issue, Thingspeak works fine if I manage the wifi connection in the conventional way but when I use WiFi Manager it crashes. Any clues?