Coder Social home page Coder Social logo

thissmarthouse / coogleiot Goto Github PK

View Code? Open in Web Editor NEW
120.0 18.0 29.0 536 KB

A ESP8266 Library for easy IOT device development

Home Page: https://www.thissmarthouse.net/coogleiot/

License: Other

C++ 24.14% C 74.50% HTML 1.36%
esp8266 arduino-library esp8266-arduino mqtt-client mqtt

coogleiot's Introduction

CoogleIOT

A ESP8266 Library for easy IOT device development.

The CoogleIOT library was created to make building IOT devices on the ESP8266 microcontroller easier by providing a solid encapsulated framework for most of the common things you want to do on an IOT device, including:

  • Captive Portal for configuration of the device - allowing you to configure the AP name, the Wifi Client, and the built in MQTT Client. Just connect to the AP and configure (mobile friendly).
  • Built in persistent logging mechanisms using SPIFFS filesystem (also available for viewing from the web interface)
  • Built in MQTT client (provided by PubSubClient)
  • Built in UI libraries for the device (Mini.css for style, jquery 3.x for Javascript) that can be served from the AP using the /css or /jquery URLs
  • Built in NTP client for access to local date / time on device
  • Built in DNS Server during configuration for captive portal support when connected to the device as an AP directly
  • Built in Security-minded tools like HTML Escaping and other filters to prevent malicious inputs
  • Built in OTA firmware update support. Can both upload a new firmware from the UI or pull a new one down from a server
  • Built in Timer allows you to create very clean timings for measurements, et.c (i.e. read sensor every x minutes)

Screenshots

WiFi Configuration

Wifi Configuration

MQTT Client Configuration

MQTT Configuration

System Configuration

System Configuration

Status Page

Status Page

Example

CoogleIOT is designed to hang out in the background so your sketches are focused on the things you actually want to work on without having to worry about things like WiFi or MQTT clients. Here is an example of using it to control a Garage Door w/open and close sensors:

/* GarageDoor-Opener.h */
#ifndef GARAGEDOOR_OPENER_H
#define GARAGEDOOR_OPENER_H

#define SERIAL_BAUD 115200

#define OPEN_SENSOR_PIN 2   // The pin that detects when the door is closed
#define CLOSE_SENSOR_PIN 5   // The pin that detects when the door is open
#define OPEN_SWTICH_PIN 14    // The pin that activates the open / close door action
#define LIGHT_SWITCH_PIN 4  // The pin that turns the light on / off

#define GARAGE_DOOR_STATUS_TOPIC "/status/garage-door"
#define GARAGE_DOOR_ACTION_TOPIC_DOOR "/garage-door/door"
#define GARAGE_DOOR_ACTION_TOPIC_LIGHT "/garage-door/light"
#define GARAGE_DOOR_MQTT_CLIENT_ID "garage-door"

#include <Arduino.h>

typedef enum {
    GD_OPEN,
    GD_CLOSED,
    GD_OPENING,
    GD_CLOSING,
    GD_UNKNOWN
} GarageDoorState;

#endif

#include <CoogleIOT.h>
#include "GarageDoor-Opener.h"

CoogleIOT *iot;
PubSubClient *mqtt;

GarageDoorState _currentState = GD_UNKNOWN;

String getDoorStateAsString(GarageDoorState state)
{
	switch(state) {
		case GD_OPEN:
			return String("open");
		case GD_CLOSED:
			return String("closed");
		case GD_OPENING:
			return String("opening");
		case GD_CLOSING:
			return String("closing");
		case GD_UNKNOWN:
			return String("unknown");
	}

	iot->warn("Garage Door State Value Unknown!");

	return String("unknown");
}

GarageDoorState getGarageDoorState()
{
	bool isClosed, isOpen;
	GarageDoorState retval = GD_UNKNOWN;

	isOpen = digitalRead(OPEN_SENSOR_PIN) == LOW;
	isClosed = digitalRead(CLOSE_SENSOR_PIN) == LOW;


	if(isOpen && isClosed) {
		iot->error("Can't be both open and closed at the same time! Sensor failure!");

		retval = GD_UNKNOWN;
		return retval;
	}

	if(!isOpen && isClosed) {
		retval = GD_CLOSED;
		return retval;
	}

	if(isOpen && !isClosed) {
		retval = GD_OPEN;
		return retval;
	}

	if(!isOpen && !isClosed) {

		if((_currentState == GD_OPEN) || (_currentState == GD_CLOSING)) {
			retval = GD_CLOSING;
			return retval;
		}

		if((_currentState == GD_CLOSED) || (_currentState == GD_OPENING)) {
			retval = GD_OPENING;
			return retval;
		}
	}

	retval = GD_UNKNOWN;
	return retval;
}

void triggerDoor()
{
	iot->info("Triggering Garage Door Open");
	digitalWrite(OPEN_SWTICH_PIN, LOW);
	delay(200);
	digitalWrite(OPEN_SWTICH_PIN, HIGH);
}

void triggerLight()
{
	iot->info("Triggering Garage Door Light");
	digitalWrite(LIGHT_SWITCH_PIN, LOW);
	delay(200);
	digitalWrite(LIGHT_SWITCH_PIN, HIGH);

}

void setup()
{
	iot = new CoogleIOT(LED_BUILTIN);

	iot->enableSerial(SERIAL_BAUD)
        .setMQTTClientId(GARAGE_DOOR_MQTT_CLIENT_ID)
	    .initialize();

	pinMode(OPEN_SWTICH_PIN, OUTPUT);
	pinMode(LIGHT_SWITCH_PIN, OUTPUT);
	pinMode(OPEN_SENSOR_PIN, INPUT_PULLUP);
	pinMode(CLOSE_SENSOR_PIN, INPUT_PULLUP);

	digitalWrite(OPEN_SWTICH_PIN, HIGH);
	digitalWrite(LIGHT_SWITCH_PIN, HIGH);

	if(iot->mqttActive()) {
		mqtt = iot->getMQTTClient();

		mqtt->setCallback(mqttCallbackHandler);

		iot->logPrintf(INFO, "Subscribed to Door-Open Topic: %s", GARAGE_DOOR_ACTION_TOPIC_DOOR);
		iot->logPrintf(INFO, "Subscribed to Light-Activate Topic: %s", GARAGE_DOOR_ACTION_TOPIC_LIGHT);

		mqtt->subscribe(GARAGE_DOOR_ACTION_TOPIC_DOOR);
		mqtt->subscribe(GARAGE_DOOR_ACTION_TOPIC_LIGHT);

		mqtt->publish(GARAGE_DOOR_STATUS_TOPIC, getDoorStateAsString(_currentState).c_str(), true);

		iot->info("Garage Door Opener Initialized");

	} else {
		iot->error("MQTT Not initialized, Garage Door Opener Inactive");
	}
}

void loop()
{
	GarageDoorState liveState;

	iot->loop();

	if(iot->mqttActive()) {
		liveState = getGarageDoorState();

		if(liveState != _currentState) {
			mqtt->publish(GARAGE_DOOR_STATUS_TOPIC, getDoorStateAsString(liveState).c_str(), true);
			_currentState = liveState;
		}
	}

}

void mqttCallbackHandler(char *topic, byte *payload, unsigned int length)
{
	String action;
	char *payloadStr;

	if(strcmp(topic, GARAGE_DOOR_ACTION_TOPIC_DOOR) == 0) {

		iot->info("Handling Garage Door Action Request");
		iot->flashStatus(200, 1);
		triggerDoor();

	} else if(strcmp(topic, GARAGE_DOOR_ACTION_TOPIC_LIGHT) == 0) {

		iot->info("Handing Garage Door Light Request");
		iot->flashStatus(200, 2);
		triggerLight();

	}
}

There are other projects that use this library which serve as great examples of it's use as well. You should probably check out these:

Coogle Switch - A CoogleIOT-powered ESP8266 sketch for creating smart switches that operate over MQTT (controlling a relay module of configured sized). Just set up which pins your relay operates on and it takes care of all the MQTT topics, etc. you need for it to work.

Where's my Device?

When MQTT is enabled, CoogleIOT automatically sends a periodic heartbeat message to /coogleiot/devices/<client_id> containing a JSON payload with useful information:

{ 
    "timestamp" : "2017-10-27 05:27:13", 
    "ip" : "192.168.1.130", 
    "coogleiot_version" : "1.2.1", 
    "client_id" : "bbq-temp-probe" 
}

If running multiple CoogleIOT devices this can be very useful to keep track of them all by just subscribing to the /coogleiot/devices/# wildcard channel which will capture all the heartbeat transmissions.

MQTT Client Notes

Presently, due to This Issue in the MQTT client used by CoogleIOT it is important that you compile your sketches using the MQTT_MAX_PACKET_SIZE flag set to a reasonable value (we recommend 512). Without this flag, larger MQTT packets (i.e. long topic names) will not be sent properly.

Please consult your build envrionment's documentation on how to set this compile-time variable. (hint: -DMQTT_MAX_PACKET_SIZE 512 works)

API

CoogleIOT is an evolving code base, so this API may change before this document is updated to reflect that. The best source is the source. When possible CoogleIOT uses a fluent interface, allowing you to chain method calls together:

  // Chaining method calls together
  iot->enableSerial(115200)
     ->initialize();

void CoogleIOT::CoogleIOT(status_led_pin = NULL) The library constructor. You may provide an optional pin to use for a status LED which will be used to indicate different states the device can be in (i.e. WiFi initializing, etc.)

bool CoogleIOT::initialize() Must be called in setup() of your sketch to initialize the library and it's components

void CoogleIOT::loop() Must be called in loop() of your sketch

CoogleIOT& CoogleIOT::enableSerial(int baud = 115200) Enables Serial output from the IOT library. Will initialize the Serial object for you at the baud rate specified if not already initialized.

PubSubClient* CoogleIOT::getMQTTClient() Return a pointer to the built in PubSubClient to use in your sketch

bool CoogleIOT::serialEnabled() Returns true if Serial is enabled

CoogleIOT& CoogleIOT::flashStatus(speed_in_ms, repeat = 5) Flashes the defined pin / LED at a speed, repeating as defined (5 times by default)

CoogleIOT& CoogleIOT::flashSOS() Flashes the status pin / LED in an SOS pattern (useful to indicate an error)

CoogleIOT& CoogleIOT::resetEEProm() Resets the EEPROM memory used by CoogleIOT to NULL, effectively "factory resetting" the device

void CoogleIOT::restartDevice() Restarts the device. Due to This Bug, you must physically press the restart button on the ESP8266 after flashing via Serial. If you fail to do that, this command will hang the device.

String CoogleIOT::filterAscii() Filters the provided string of anything that is not a printable ASCII character

bool CoogleIOT::verifyFlashConfiguration() Verifies the Flash configuration for the device (what the device supports, vs. what the device is set as in your sketch) is correct.

CoogleIOT& CoogleIOT::syncNTPTime(int offsetSeconds, int daylightOffsetSeconds) Synchronizes and sets the local device date / time based on NTP servers. Must have a working WiFi connection to use this method. The first parameter is the number of seconds local time is offset from UTC time (i.e. -5 hrs in seconds is America/New York). The second parameter is the number of seconds to offset based on daylight savings.

String CoogleIOT::getWiFiStatus() Returns a string representing the current state of the WiFi Client

bool CoogleIOT::mqttActive() Returns true/false indicating if the MQTT client is active and ready to use or not

bool CoogleIOT::dnsActive() Returns true/false if the integrated captive portal DNS is enabled or not

bool CoogleIOT::ntpActive() Returns true/false if the NTP client is online and synchronizing with NTP time servers

bool CoogleIOT::firmwareClientActive() Returns true/false if the periodic firmware client (that will download a new firmware from a web server) is active or not. If active, the Firmware client will check every 30 minutes for a new firmware at the configured URL

bool CoogleIOT::apStatus() Returns true/false if the AP of the device is active or not.

CoogleIOT& CoogleIOT::registerTimer(int interval, callback) Create a callback timer that will call callback (void function with no params) every interval milliseconds. You can turn off the timer by passing 0 as the interval. Useful for taking a sensor reading every X seconds, etc.

void CoogleIOT::checkForFirmwareUpdate() Performs a check against the specified Firmware Server endpoint for a new version of this device's firmware. If a new version exists it performs the upgrade.

The following getters/setters are pretty self explainatory. Each getter will return a String object of the value from EEPROM (or another primiative data type), with a matching setter:

String CoogleIOT::getRemoteAPName() CoogleIOT& CoogleIOT::setRemoteAPName(String) String CoogleIOT::getRemoteAPPassword() CoogleIOT& CoogleIOT::setRemoteAPPassword(String) String CoogleIOT::getMQTTHostname() CoogleIOT& CoogleIOT::setMQTTHostname(String) String CoogleIOT::getMQTTUsername() CoogleIOT& CoogleIOT::setMQTTUsername(String) String CoogleIOT::getMQTTPassword() CoogleIOT& CoogleIOT::setMQTTPassword(String) String CoogleIOT::getMQTTClientId() CoogleIOT& CoogleIOT::setMQTTClientId() int CoogleIOT::getMQTTPort() CoogleIOT& CoogleIOT::setMQTTPort(int) String CoogleIOT::getAPName() CoogleIOT& CoogleIOT::setAPName(String) String CoogleIOT::getAPPassword() CoogleIOT& CoogleIOT::setAPPassword(String) String CoogleIOT::getFirmwareUpdateUrl() CoogleIOT& CoogleIOT::setFirmwareUpdateUrl(String)

CoogleIOT Firmware Configuration

The Firmware default values and settings are defined in the CoogleIOTConfig.h file and can be overriden by providing new #define statements

#define COOGLEIOT_STATUS_INIT 500 Defines the status LED flash speed in MS for initial initialization

#define COOGLEIOT_STATUS_WIFI_INIT 250 Defines the status LED flash speed for WiFi initialization

#define COOGLEIOT_STATUS_MQTT_INIT 100 Defines the status LED flash speed for MQTT initialization

#define COOGLEIOT_AP "COOGLEIOT_ Defines the prepended string used for the default AP name. The remainder of the AP name will be a randomly generated number (i.e. COOGLEIOT_234934)

#define COOGLEIOT_AP_DEFAULT_PASSWORD "coogleiot" The default AP password

#define COOGLEIOT_DEFAULT_MQTT_CLIENT_ID "coogleIoT" The default MQTT client ID

#define COOGLEIOT_DEFAULT_MQTT_PORT 1883 The default MQTT Port

#define COOGLEIOT_TIMEZONE_OFFSET ((3600 * 5) * -1) The default NTP Timezone offset (America/New York)

#define COOGLEIOT_DAYLIGHT_OFFSET 0 The default NTP Daylight Offset

#define COOGLEIOT_NTP_SERVER_1 "pool.ntp.org" #define COOGLEIOT_NTP_SERVER_2 "time.nist.gov" #define COOGLEIOT_NTP_SERVER_3 "time.google.com" The three default NTP servers to attempt to synchronize with

#define COOGLEIOT_FIRMWARE_UPDATE_CHECK_MS 54000000 // 15 Minutes in Milliseconds The frequency that we will check for a new Firmware Update if the server is configured. Defaults to 15 minutes.

#define COOGLEIOT_DNS_PORT 53 The default DNS port

#define COOGLE_EEPROM_EEPROM_SIZE 1024 The amount of EEPROM memory allocated to CoogleIOT, 1kb default.

IMPORTANT NOTE: Do NOT reduce this value below it's default value unless you really know what you are doing, otherwise you will break the firmware.

#define COOGLEIOT_WEBSERVER_PORT 80 The default Webserver port for the configuration system

#define COOGLEIOT_DEBUG If defined, it will enable debugging mode for CoogleIOT which will dump lots of debugging data to the Serial port (if enabled)

coogleiot's People

Contributors

coogle avatar per1234 avatar rlerdorf avatar snappy46 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coogleiot's Issues

MQTT subscribtions are cleared on reconnect

Currently when CoogleIOT reconnects to the mqtt server it does so with the cleanSession flag set to true. This results in all subscribtions being cleared. As such it would be helpful to either have a callback that gets called after a successful reconnect or having CoogleIOT automatically restore all subscriptions.

Example .h file missing!

I have downloaded and installed your library, but am unable to compile your example as the GarageDoor-Opener.h file is missing. I am unable to find it on GitHub.
Can you please provide the file?

Failed to connect to MQTT Server!

Hi,

The library looks great, I'm keen to start using it however I am unable to connect to an MQTT server.

I am trying to connect to;
host: broker.mqtt-dashboard.com
port: 1883

I've tried connecting to a few different servers but they all result in a loop of the following error.
[INFO 2018-02-12 22:52:31] Attempting to Connect to MQTT Server
[ERROR 2018-02-12 22:52:31] Failed to connect to MQTT Server!
[INFO 2018-02-12 22:52:31] Failed too many times to establish a MQTT connection. Restarting Device.

I've tried using the GarageDoorOpener, Coogle Feeder and Coogle Switch in case I was missing something in my code but they all have the same result.

If I use the PubSubClient sketch (https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_esp8266/mqtt_esp8266.ino) then I can connect to an MQTT server without issue.

Do you have any suggestions as to how I can get a more verbose error message?

Thanks in advance.

GetTimestampAsString return month is off by 1

Not sure if this is an issue with the time library that I am using or this code. Basically the time pointer function for p_tm->tm_month returns a value between 0 (January) to 11 (December); therefore the timestamp it is off by a month ex: "timestamp" : "2018-05-13 19:50:24" versus "timestamp" : "2018-06-13 19:50:24" for June 13 2018.

This might be caused by the time library that I am using; I don't know. I am using the following library:
Git Repo: "https://github.com/PaulStoffregen/Time"
Webpage: "http://playground.arduino.cc/Code/Time"

If not cause by the time library then it's an easy fix which I can provide. Thank you for a great library; just wish I would have found this about 6 months ago instead of a few weeks ago; it would have saved me a lot of time.

WifiClientPrint.h - wrong file name

Error during compiling: CoogleIOT/src/CoogleIOTWebserver.h:29:29: fatal error: WifiClientPrint.h: No such file or directory
#include "WifiClientPrint.h"

Apparently the src file name is wrong "WiFiClientPrint.h" (capital "F")

Change the filename back to "WifiClientPrint.h" would solve the issue.

Exception (28): after configuration

I get an exception after configuration when it restarts, what is the problem?


[INFO UKWN] Connecting to remote AP
[INFO UKWN] Connected to Remote Access Point!
[INFO UKWN] Our IP Address is:
[INFO UKWN] 192.168.1.127

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

ctx: cont 
sp: 3fff1430 end: 3fff17a0 offset: 01a0

>>>stack>>>
3fff15d0:  3fff21cc 4020c9fc 3fff30a4 3fff0778  
3fff15e0:  3fffdad0 3ffe995c 3fff30a4 40208fb6  
3fff15f0:  00000022 40103ee1 00040000 00000000  
3fff1600:  3ffeeec0 40102ebe 00000000 4000050c  
3fff1610:  3fffc278 40102d14 00000000 4000050c  
3fff1620:  3fffc278 40102d14 3fffc200 00000022  
3fff1630:  3fff1640 00000000 0000001f 40105789  
3fff1640:  40206e95 00000030 0000000d ffffffff  
3fff1650:  40206e8c 00000000 000003e8 00000000  
3fff1660:  00000003 00000101 00000000 fffffffe  
3fff1670:  ffffffff 3fffc6fc 00000078 00048ac6  
3fff1680:  00000000 00000000 3fff0526 00000030  
3fff1690:  00000000 3fff17f4 3fff0778 00000030  
3fff16a0:  00000000 00000000 00000001 3fff0771  
3fff16b0:  00000000 3fffdad0 3fff0778 00000030  
3fff16c0:  00000190 3fffc6fc 00000001 3fff0771  
3fff16d0:  00000000 3fffdad0 3fff0778 00000030  
3fff16e0:  00000000 3fffdad0 3fff0778 00000030  
3fff16f0:  00000000 00000000 00000000 4021293f  
3fff1700:  3fff0694 000005a4 000005a4 4010020c  
3fff1710:  3fffdad0 3fff052c 3fff1740 4010068c  
3fff1720:  3fff0694 00000218 00000218 4010020c  
3fff1730:  00000000 00000000 00000000 3fff5454  
3fff1740:  0000000f 00000000 3fff2e8c 0000000f  
3fff1750:  00000000 3fff30a4 3fff30a4 40206c60  
3fff1760:  00000000 00000000 00000000 3fff0778  
3fff1770:  3fffdad0 00000000 3fff052c 40206f93  
3fff1780:  3fffdad0 00000000 3fff0771 4021350c  
3fff1790:  feefeffe feefeffe 3fff0780 40100744  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Exception 28 crash after first config

A stripped down garagedooropener crashes after first config via integrate AP. I set the MQTT port and after joining the WIFI the ESP Crashes:

[INFO UKWN] Coogle IOT v1.3.1 initializing..
09:35:44.372 -> [DEBUG UKWN] Introspecting on-board Flash Memory:
09:35:44.372 -> [DEBUG UKWN] Flash ID: 00164020
09:35:44.372 -> [DEBUG UKWN] Flash real size: 4194304
09:35:44.372 -> [DEBUG UKWN] Flash IDE Size: 4194304
09:35:44.372 -> [DEBUG UKWN] Flash IDE Speed: 40000000
09:35:44.372 -> [DEBUG UKWN] Flash IDE Mode: 1073645354
09:35:44.372 -> [DEBUG UKWN] Flash Chip Configuration Verified: OK
[INFO UKWN] EEPROM not initialized for platform, erasing..
[INFO UKWN] Log file successfully opened
[INFO UKWN] Cannot connect WiFi client, no remote AP specified
09:35:59.582 -> [ERROR UKWN] Failed to connect to remote AP
09:35:59.582 -> [INFO UKWN] Enabling Configuration Mode
09:35:59.582 -> [INFO UKWN] No AP Password found in memory
09:35:59.582 -> [INFO UKWN] Setting to default password: coogleiot
[INFO UKWN] No AP Name found in memory. Auto-generating AP name.
09:35:59.615 -> [INFO UKWN] Setting AP Name To: 
09:35:59.615 -> [INFO UKWN] COOGLEIOT_893542
[INFO UKWN] Intiailzing Access Point
[INFO UKWN] Local IP Address: 
[INFO UKWN] 192.168.0.1
09:36:01.503 -> [INFO UKWN] Initializing DNS Server
09:36:01.503 -> [INFO UKWN] Creating Configuration Web Server
09:36:01.503 -> [INFO UKWN] Initializing Webserver
09:36:01.503 -> [INFO UKWN] Webserver Initiailized!
[INFO UKWN] Not connected to WiFi. Attempting reconnection.
[INFO UKWN] Connecting to remote AP
[INFO UKWN] Connected to Remote Access Point!
09:37:01.796 -> [INFO UKWN] Our IP Address is:
09:37:01.796 -> [INFO UKWN] 192.168.227.159

09:37:01.995 -> Exception (28):
09:37:01.995 -> epc1=0x4021605b epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000008 depc=0x00000000
09:37:01.995 -> 
09:37:01.995 -> >>>stack>>>
09:37:01.995 -> 
09:37:01.995 -> ctx: cont
09:37:01.995 -> sp: 3ffffc60 end: 3fffffc0 offset: 01a0
09:37:02.028 -> 3ffffe00:  3fffdad0 3ffe9894 3fff0cb4 402093ee  
09:37:02.028 -> 3ffffe10:  401039a2 0000007f 7fffffff 00000000  
09:37:02.028 -> 3ffffe20:  0000007f 4010379e 00040000 4010233a  
09:37:02.028 -> 3ffffe30:  40102817 00080000 4010277a 00000100  
09:37:02.028 -> 3ffffe40:  00000000 0000007f 00000000 4000050c  
09:37:02.028 -> 3ffffe50:  00000000 00000000 0000001f 40105135  
09:37:02.028 -> 3ffffe60:  4000050c 00080000 00000000 4000050c  
09:37:02.028 -> 3ffffe70:  4021596b 00000030 00000010 ffffffff  
09:37:02.061 -> 3ffffe80:  40214adf 00000000 3fff1c40 ffff8000  
09:37:02.061 -> 3ffffe90:  000000f2 3fff26b8 00000000 fffffffe  
09:37:02.061 -> 3ffffea0:  00000190 3fffc6fc 00000001 3ffefeb0  
09:37:02.061 -> 3ffffeb0:  00000000 3fffdad0 3ffefee0 00000030  
09:37:02.061 -> 3ffffec0:  00000000 00000000 00000000 fffffffe  
09:37:02.061 -> 3ffffed0:  ffffffff 3fffc6fc 00000001 3ffefeb0  
09:37:02.061 -> 3ffffee0:  00000000 3fffdad0 3ffefee0 00000030  
09:37:02.155 -> 3ffffef0:  00000000 3fffdad0 3ffefee0 00000030  
09:37:02.155 -> 3fffff00:  00000000 3fffdad0 3ffefee0 00000030  
09:37:02.155 -> 3fffff10:  3ffef710 3fff0d58 00000000 40213de8  
09:37:02.155 -> 3fffff20:  00000001 006ab885 3fff0d58 40213e04  
09:37:02.155 -> 3fffff30:  3ffefd50 3ffeff58 3ffe95d4 402097f3  
09:37:02.155 -> 3fffff40:  3ffeff74 00000147 00000147 40100630  
09:37:02.155 -> 3fffff50:  00000000 00000000 00000000 3fff26bc  
09:37:02.155 -> 3fffff60:  0000000f 00000000 3fff1c44 0000000f  
09:37:02.155 -> 3fffff70:  00000000 00000000 3fff0cb4 40213e04  
09:37:02.155 -> 3fffff80:  3fffdad0 00000000 3fff0cb4 3ffefee0  
09:37:02.155 -> 3fffff90:  3fffdad0 00000000 3ffefeb0 402073e7  
09:37:02.155 -> 3fffffa0:  3fffdad0 00000000 3ffefeb0 40214adc  
09:37:02.155 -> 3fffffb0:  feefeffe feefeffe 3ffe8544 40100ad1  
09:37:02.155 -> <<<stack<<<
09:37:02.155 -> 
09:37:02.155 ->  ets Jan  8 2013,rst cause:2, boot mode:(1,6)
09:37:02.155 -> 

Decoding the crash returns:

Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x4021605b: PubSubClient::connected() at /home/flo/Arduino/libraries/PubSubClient/src/PubSubClient.cpp line 603
EXCVADDR: 0x00000008

Decoding stack results
0x402093ee: CoogleIOT::loop() at /home/flo/Arduino/libraries/CoogleIOT/src/CoogleIOT.cpp line 323
0x4021596b: run_scheduled_functions() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/Schedule.cpp line 68
0x40214adf: loop_wrapper() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/core_esp8266_main.cpp line 126
0x40213de8: String::invalidate() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.cpp line 141
0x40213e04: String::~String() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.cpp line 125
0x402097f3: CoogleIOT::initialize() at /home/flo/Arduino/libraries/CoogleIOT/src/CoogleIOT.cpp line 605
0x40100630: _umm_free at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/umm_malloc/umm_malloc.c line 1300
0x40213e04: String::~String() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.cpp line 125
0x402073e7: loop() at /home/flo/projects/arduino/tempsensor/tempsensor.ino line 144
0x40214adc: loop_wrapper() at /home/flo/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/core_esp8266_main.cpp line 125

The line is

601 boolean PubSubClient::connected() {
602     boolean rc;
603     if (_client == NULL ) {
604         rc = false;
605     } else {

Which is interesting - As _client is a private object pointer in the PubSubClient Class it seems there is no PubSubClient object instantiated or the pointer is NULL.

And no there is not a valid MQTT endpoint configured and yes i have increased the MAX packet size in MQTT.

Flo

CoogleIOT issues with newer esp8266 Arduino cores (3.0.x)

Changes needed to make CoogleIOT compile and run on current esp8266 cores

1) Function removed from ESP8222 core API

From ESP8266 Arduino core 3.0.0 version onwards the following prototype (previously deprecated) has been removed:

HTTPUpdateResult ESPhttpUpdate::update(const char* host, int& port, const char* uri, const char * currentVersion);

This methotd is used in CoogleIOT::checkForFirmwareUpdate() at CoogleIOT.cpp line 987 (library version 1.3.1).

Od call:

firmwareUpdateStatus = ESPhttpUpdate.update(URL.m_Host.c_str(), port, URL.m_Path.c_str(), COOGLEIOT_VERSION);

The current prototype is

HTTPUpdateResult ESP8266HTTPUpdate::update(WiFiClient & client, const String & host, uint16_t port, const String & uri, const String & currentVersion) 

The call sholud be replaced with something like (it worked for me):

const String ver_str = COOGLEIOT_VERSION;
const String uri_str = URL.m_Path.c_str();
const String host_str = URL.m_Host.c_str();
firmwareUpdateStatus = ESPhttpUpdate.update(espClient, host_str, port, uri_str, ver_str);  

**2) Missing return value in CoogleIOT::verifyFlashConfiguration();**

The memeber function bool CoogleIOT::verifyFlashConfiguration() lacks a 'return ` statement. Quite puzzingly (for me) the compiler does not complain, but the code crashes on return of this function. The ESP exception decoder does not help too much, by the way, as it locates the fault elsewhere.

Just adding

return true;

at the end of the function (line 367) solves the problem and the initialization proceeds normally.

Linking problems with DNSServer with arduino-mk

Hi,
when building with the Arduino IDE everythings fine - But building with arduino-mk fails with a linker error concerning DNSServer:

/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -g -Os -nostdlib -Wl,--no-check-sections -u call_user_start -u _printf_float -u _scanf_float -Wl,-static -L/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/tools/sdk/lib -L/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/tools/sdk/ld -L/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m1m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o build.nodemcu-2.4.2/tempsensor.elf -Wl,--start-group ./build.nodemcu-2.4.2/tempsensor.ino.cpp.o ./build.nodemcu-2.4.2/libraries/CoogleEEPROM.cpp.o ./build.nodemcu-2.4.2/libraries/CoogleIOTWebserver.cpp.o ./build.nodemcu-2.4.2/libraries/CoogleIOT.cpp.o ./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o ./build.nodemcu-2.4.2/libraries/LUrlParser.cpp.o ./build.nodemcu-2.4.2/libraries/PubSubClient.cpp.o ./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o ./build.nodemcu-2.4.2/libraries/EEPROM.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266HTTPClient.cpp.o ./build.nodemcu-2.4.2/libraries/Parsing.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WebServer.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WebServerSecureBearSSL.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WebServerSecureAxTLS.cpp.o ./build.nodemcu-2.4.2/libraries/mimetable.cpp.o ./build.nodemcu-2.4.2/libraries/BearSSLHelpers.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFiScan.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFiSTA.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFiAP.cpp.o ./build.nodemcu-2.4.2/libraries/CertStoreBearSSL.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiServerSecureBearSSL.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFiMulti.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFi.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266WiFiGeneric.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiUdp.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiServer.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiClient.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiServerSecureAxTLS.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiClientSecureBearSSL.cpp.o ./build.nodemcu-2.4.2/libraries/WiFiClientSecureAxTLS.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266httpUpdate.cpp.o ./build.nodemcu-2.4.2/libraries/ESP8266mDNS.cpp.o ./build.nodemcu-2.4.2/core/core.a -lhal -lphy -lpp -lnet80211 -llwip_gcc -lwpa -lcrypto -lmain -lwps -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L./build.nodemcu-2.4.2
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o: In function `DNSServer::setTTL(unsigned int const&)':
/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:6: multiple definition of `DNSServer::DNSServer()'
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o:/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:6: first defined here
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o: In function `DNSServer::setTTL(unsigned int const&)':
/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:6: multiple definition of `DNSServer::DNSServer()'
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o:/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:6: first defined here
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o: In function `String::operator+=(char)':
/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:28: multiple definition of `DNSServer::setErrorReplyCode(DNSReplyCode const&)'
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o:/home/flo/projects/arduino/tempsensor/Esp8266-Arduino-Makefile/esp8266-2.4.2/libraries/DNSServer/src/DNSServer.cpp:28: first defined here
./build.nodemcu-2.4.2/libraries/DNSServer.cpp.o: In function `DNSServer::processNextRequest()':

I trying to build with various combinations of

ARDUINO_LIBS=DNSServer CoogleIOT ESP8266HTTPClient ESP8266WiFi
USER_DEFINE=-DARDUINO_ESP8266_ESP01 -DMQTT_MAX_PACKET_SIZE=512

Flo

Basic CoogleIoT example crashes device?

Hi.

I don't know whether CoogleIoT does something weird, or it is me who doesn't really understand how to use it or setup properly.

I've downloaded CoogleIoT v1.3.1 (github) and flashed the following sample firmware to a LoLin NodeMCU v3 dev board. After flashing it, the device does not stops flashing the main led. No wifi hotspot is published, and a lot of garbage is printed in the Serial Monitor of the Arduino studio.

#include <ESP8266WiFi.h>
#include <CoogleIOT.h>

const int SERIAL_BAUD = 115200;
const int SleepTime = 5e6;

CoogleIOT *iot;

void setup() {
  iot = new CoogleIOT(LED_BUILTIN);

  iot->enableSerial(SERIAL_BAUD)
    .initialize();

  iot->info("Setup finalised");
}

void loop() {
  iot->loop();
  iot->info("Going to sleep");
  ESP.deepSleep(SleepTime); // Going to sleep. Pins are circuited correctly.
}

Any clue? Thanks in advance.

Custom items

It would be nice if it is possible to use CoogleIOT's logic to customize your own sketch, like:

  • add custom config-items to edit in the webinterface
  • read/write custom variables to eeprom
  • create and integrate custom webpages
    (or maybe this is possible already and I don't know how...)

Thanks for the great work.

Constant reboot

Trying to write a very bare bones application to get started. Works initially, sets up an AP, but when I enter SSID/password to connect as a client, after it reboots, it connects to the wifi ok, goes thru initialization but then constantly reboots after initialization with this message:

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

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

Here's the code I'm running (I added the resetEEProm() so I could clear it, but it doesn't reset the EEProm). After setting up client wifi, it just constantly reboots.

#include <CoogleIOT.h>

CoogleIOT *iot;
PubSubClient *mqtt;
#define SERIAL_BAUD 115200

void setup()
{
iot = new CoogleIOT(LED_BUILTIN);
iot->enableSerial(SERIAL_BAUD);
iot->resetEEProm();
iot->initialize();

}

void loop()
{
iot->loop();
}

configuration when wifi config is invalid

if you setup a node with a mistake in the SSID or password,

the node will repeatedly attempt to connect (10 times) - then it will reset and do this again.

however during that process, there is no loop for the dns or web server, so it is impossible to re-configure the node to be able to use the correct credentials (save for wiping it and starting again).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.