From cdaf5c4f13cdbee715880a70902d4804ceadc839 Mon Sep 17 00:00:00 2001 From: flexiti Date: Thu, 10 Mar 2016 10:51:43 +0100 Subject: [PATCH 1/9] Blink_RTOS_sample --- samples/Basic_Blink_RTOS/Makefile | 24 +++++++ samples/Basic_Blink_RTOS/Makefile-user.mk | 41 ++++++++++++ samples/Basic_Blink_RTOS/app/application.cpp | 62 +++++++++++++++++++ .../Basic_Blink_RTOS/include/user_config.h | 7 +++ 4 files changed, 134 insertions(+) create mode 100644 samples/Basic_Blink_RTOS/Makefile create mode 100644 samples/Basic_Blink_RTOS/Makefile-user.mk create mode 100644 samples/Basic_Blink_RTOS/app/application.cpp create mode 100644 samples/Basic_Blink_RTOS/include/user_config.h diff --git a/samples/Basic_Blink_RTOS/Makefile b/samples/Basic_Blink_RTOS/Makefile new file mode 100644 index 0000000..16d76cd --- /dev/null +++ b/samples/Basic_Blink_RTOS/Makefile @@ -0,0 +1,24 @@ +##################################################################### +#### Please don't change this file. Use Makefile-user.mk instead #### +##################################################################### +# Including user Makefile. +# Should be used to set project-specific parameters +include ./Makefile-user.mk + +# Important parameters check. +# We need to make sure SMING_HOME and ESP_HOME variables are set. +# You can use Makefile-user.mk in each project or use enviromental variables to set it globally. + +ifndef SMING_HOME +$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) +endif +ifndef ESP_HOME +$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) +endif + +# Include main Sming Makefile +ifeq ($(RBOOT_ENABLED), 1) +include $(SMING_HOME)/Makefile-rboot.mk +else +include $(SMING_HOME)/Makefile-project.mk +endif diff --git a/samples/Basic_Blink_RTOS/Makefile-user.mk b/samples/Basic_Blink_RTOS/Makefile-user.mk new file mode 100644 index 0000000..9230c3b --- /dev/null +++ b/samples/Basic_Blink_RTOS/Makefile-user.mk @@ -0,0 +1,41 @@ +## Local build configuration +## Parameters configured here will override default and ENV values. +## Uncomment and change examples: + +## Add your source directories here separated by space +# MODULES = app +# EXTRA_INCDIR = include + +## ESP_HOME sets the path where ESP tools and SDK are located. +## Windows: +ESP_HOME = c:/espressif + +## MacOS / Linux: +# ESP_HOME = /opt/esp-open-sdk + +## SMING_HOME sets the path where Sming framework is located. +## Windows: +SMING_HOME = c:/tools/SmingRTOS/sming + +## MacOS / Linux +# SMING_HOME = /opt/sming/Sming + +## COM port parameter is reqruied to flash firmware correctly. +## Windows: + COM_PORT = COM6 + +## MacOS / Linux: +# COM_PORT = /dev/tty.usbserial + +## Com port speed +# COM_SPEED = 115200 + +## Configure flash parameters (for ESP12-E and other new boards): +# SPI_MODE = dio + +## SPIFFS options +DISABLE_SPIFFS = 1 +# SPIFF_FILES = files + +ESPTOOL2 ?= c:/tools/sming/esptool2 + diff --git a/samples/Basic_Blink_RTOS/app/application.cpp b/samples/Basic_Blink_RTOS/app/application.cpp new file mode 100644 index 0000000..caef5ff --- /dev/null +++ b/samples/Basic_Blink_RTOS/app/application.cpp @@ -0,0 +1,62 @@ +#include +#include + + +#define LEDB_PIN 2 // GPIO2 +#define LEDR_PIN 15 // GPI15 + + +bool state = true; +bool stateR = true; + +// +// actualy "portTICK_RATE_MS" (RTOS tick fro ESP8266) is set to 10 ms +// + +// ****************************** +// ledB task (our first "program") +// ****************************** +void ledB_task(void *pvParameters) +{ + + pinMode(LEDB_PIN, OUTPUT); + for(;;) + { + digitalWrite(LEDB_PIN, state); + state = !state; + // + // Perform other action here. + // + vTaskDelay(500/portTICK_RATE_MS); //Pause operation for 50 tiks (500 ms) + //create opportunities to launch another task with the same priority + } + +} +// ******************************* +// ledR task (our second "program") +// ******************************* +void ledR_task(void *pvParameters) +{ + + pinMode(LEDR_PIN, OUTPUT); + while(1) + { + digitalWrite(LEDR_PIN, stateR); + stateR = !stateR; + // + // Perform other action here. + // + vTaskDelay(250/portTICK_RATE_MS); //Pause operation for 25 tiks (250 ms) + //create opportunities to launch another task with the same priority + } + +} + + +void init() +{ + + // The creation of two task with the same priority + xTaskCreate(ledB_task, (const signed char*)"ledB_task", 256, NULL, 2, NULL); + xTaskCreate(ledR_task, (const signed char*)"ledR_task", 256, NULL, 2, NULL); +} diff --git a/samples/Basic_Blink_RTOS/include/user_config.h b/samples/Basic_Blink_RTOS/include/user_config.h new file mode 100644 index 0000000..f2a508f --- /dev/null +++ b/samples/Basic_Blink_RTOS/include/user_config.h @@ -0,0 +1,7 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +// In this file you can define Sming Runtime parameters +// For possible options see : .... + +#endif From cedef20c1f58f3a34468944e60a3a01af8211fc7 Mon Sep 17 00:00:00 2001 From: flexiti Date: Thu, 10 Mar 2016 10:54:23 +0100 Subject: [PATCH 2/9] .cproject file --- samples/Basic_Blink_RTOS/.cproject | 152 +++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 samples/Basic_Blink_RTOS/.cproject diff --git a/samples/Basic_Blink_RTOS/.cproject b/samples/Basic_Blink_RTOS/.cproject new file mode 100644 index 0000000..8e68134 --- /dev/null +++ b/samples/Basic_Blink_RTOS/.cproject @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + From a30afd22adf1e060da5aa7e54bf4e189ebc6985b Mon Sep 17 00:00:00 2001 From: flexiti Date: Thu, 10 Mar 2016 10:55:17 +0100 Subject: [PATCH 3/9] .project file --- samples/Basic_Blink_RTOS/.project | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 samples/Basic_Blink_RTOS/.project diff --git a/samples/Basic_Blink_RTOS/.project b/samples/Basic_Blink_RTOS/.project new file mode 100644 index 0000000..ac56616 --- /dev/null +++ b/samples/Basic_Blink_RTOS/.project @@ -0,0 +1,28 @@ + + + Basic_Blink_RTOS + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + From 66f018c09f6f3917fbdd0c23b1f189aee568b027 Mon Sep 17 00:00:00 2001 From: flexiti Date: Thu, 10 Mar 2016 10:57:16 +0100 Subject: [PATCH 4/9] Update Makefile-user.mk --- samples/Basic_Blink_RTOS/Makefile-user.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/Basic_Blink_RTOS/Makefile-user.mk b/samples/Basic_Blink_RTOS/Makefile-user.mk index 9230c3b..a564a12 100644 --- a/samples/Basic_Blink_RTOS/Makefile-user.mk +++ b/samples/Basic_Blink_RTOS/Makefile-user.mk @@ -8,21 +8,21 @@ ## ESP_HOME sets the path where ESP tools and SDK are located. ## Windows: -ESP_HOME = c:/espressif +# ESP_HOME = c:/espressif ## MacOS / Linux: # ESP_HOME = /opt/esp-open-sdk ## SMING_HOME sets the path where Sming framework is located. ## Windows: -SMING_HOME = c:/tools/SmingRTOS/sming +# SMING_HOME = c:/tools/SmingRTOS/sming ## MacOS / Linux # SMING_HOME = /opt/sming/Sming ## COM port parameter is reqruied to flash firmware correctly. ## Windows: - COM_PORT = COM6 +# COM_PORT = COM6 ## MacOS / Linux: # COM_PORT = /dev/tty.usbserial @@ -37,5 +37,5 @@ SMING_HOME = c:/tools/SmingRTOS/sming DISABLE_SPIFFS = 1 # SPIFF_FILES = files -ESPTOOL2 ?= c:/tools/sming/esptool2 +#ESPTOOL2 ?= c:/tools/sming/esptool2 From 79d9ebc7522a2cfe2ad0aa6a50346feb56389624 Mon Sep 17 00:00:00 2001 From: flexiti Date: Thu, 10 Mar 2016 11:00:19 +0100 Subject: [PATCH 5/9] Update application.cpp --- samples/Basic_Blink_RTOS/app/application.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/samples/Basic_Blink_RTOS/app/application.cpp b/samples/Basic_Blink_RTOS/app/application.cpp index caef5ff..8fb8b5f 100644 --- a/samples/Basic_Blink_RTOS/app/application.cpp +++ b/samples/Basic_Blink_RTOS/app/application.cpp @@ -3,14 +3,14 @@ #define LEDB_PIN 2 // GPIO2 -#define LEDR_PIN 15 // GPI15 +#define LEDR_PIN 15 // GPIO15 bool state = true; bool stateR = true; // -// actualy "portTICK_RATE_MS" (RTOS tick fro ESP8266) is set to 10 ms +// actualy "portTICK_RATE_MS" (base RTOS tick for ESP8266) is set to 10 ms // // ****************************** @@ -27,7 +27,8 @@ void ledB_task(void *pvParameters) // // Perform other action here. // - vTaskDelay(500/portTICK_RATE_MS); //Pause operation for 50 tiks (500 ms) + + vTaskDelay(500/portTICK_RATE_MS); //Pause operation for 50 ticks (500 ms) //create opportunities to launch another task with the same priority } @@ -46,7 +47,8 @@ void ledR_task(void *pvParameters) // // Perform other action here. // - vTaskDelay(250/portTICK_RATE_MS); //Pause operation for 25 tiks (250 ms) + + vTaskDelay(250/portTICK_RATE_MS); //Pause operation for 25 ticks (250 ms) //create opportunities to launch another task with the same priority } From d8b78e3e63d4c6f34c8e102aa052e131c1342c8a Mon Sep 17 00:00:00 2001 From: flexiti Date: Mon, 21 Mar 2016 09:07:58 +0100 Subject: [PATCH 6/9] MQTT ping sending modification (setPingRepeatTime added) --- sming/sming/network/MqttClient.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/sming/sming/network/MqttClient.cpp b/sming/sming/network/MqttClient.cpp index 4ee2148..941aa85 100644 --- a/sming/sming/network/MqttClient.cpp +++ b/sming/sming/network/MqttClient.cpp @@ -41,6 +41,17 @@ void MqttClient::setKeepAlive(int seconds) keepAlive = seconds; } +void MqttClient::setPingRepeatTime(int seconds) + { + if (seconds > keepAlive) + PingRepeatTime = keepAlive; + else + PingRepeatTime = seconds; + } + + + + bool MqttClient::setWill(String topic, String message, int QoS, bool retained /* = false*/) { return mqtt_set_will(&broker, topic.c_str(), message.c_str(), QoS, retained); @@ -107,6 +118,7 @@ int MqttClient::staticSendPacket(void* userInfo, const void* buf, unsigned int c { MqttClient* client = (MqttClient*)userInfo; bool sent = client->send((const char*)buf, count); + client->lastMessage = millis(); return sent ? count : 0; } @@ -298,10 +310,11 @@ err_t MqttClient::onReceive(pbuf *buf) void MqttClient::onReadyToSendData(TcpConnectionEvent sourceEvent) { - if (sleep >= 10) - { - mqtt_ping(&broker); - sleep = 0; - } - TcpClient::onReadyToSendData(sourceEvent); + // Send PINGREQ every PingRepeatTime , if there is no outgoing traffic + if (lastMessage && (millis() - lastMessage >= PingRepeatTime*1000)) + { + mqtt_ping(&broker); + } + TcpClient::onReadyToSendData(sourceEvent); + } From cc071aec81c640020a6c7145697a521e442de63f Mon Sep 17 00:00:00 2001 From: flexiti Date: Mon, 21 Mar 2016 09:12:39 +0100 Subject: [PATCH 7/9] Update MqttClient.h --- sming/sming/network/MqttClient.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sming/sming/network/MqttClient.h b/sming/sming/network/MqttClient.h index 61f167c..418dfd5 100644 --- a/sming/sming/network/MqttClient.h +++ b/sming/sming/network/MqttClient.h @@ -30,7 +30,10 @@ class MqttClient: protected TcpClient MqttClient(IPAddress serverIp, int serverPort, MqttStringSubscriptionCallback callback = NULL); virtual ~MqttClient(); - void setKeepAlive(int seconds); + + void setKeepAlive(int seconds); //send to broker + void setPingRepeatTime(int seconds); //used by client + // Sets Last Will and Testament bool setWill(String topic, String message, int QoS, bool retained = false); @@ -68,7 +71,8 @@ class MqttClient: protected TcpClient uint8_t *current; int posHeader; MqttStringSubscriptionCallback callback; - int keepAlive = 20; + int keepAlive = 60; + int PingRepeatTime = 20; String mqttCommandEnabled = ""; String mqttCommandTopic = ""; From 8c5b1095621d5ee703cf64862ed897c446d5cf19 Mon Sep 17 00:00:00 2001 From: flexiti Date: Mon, 21 Mar 2016 09:16:17 +0100 Subject: [PATCH 8/9] Update MqttClient.h --- sming/sming/network/MqttClient.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sming/sming/network/MqttClient.h b/sming/sming/network/MqttClient.h index 418dfd5..d4730b2 100644 --- a/sming/sming/network/MqttClient.h +++ b/sming/sming/network/MqttClient.h @@ -73,6 +73,7 @@ class MqttClient: protected TcpClient MqttStringSubscriptionCallback callback; int keepAlive = 60; int PingRepeatTime = 20; + unsigned long lastMessage; String mqttCommandEnabled = ""; String mqttCommandTopic = ""; From f79cefaa114f5214faf0275717af30177bcc88b6 Mon Sep 17 00:00:00 2001 From: flexiti Date: Mon, 21 Mar 2016 09:24:12 +0100 Subject: [PATCH 9/9] Update MqttClient.cpp --- sming/sming/network/MqttClient.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sming/sming/network/MqttClient.cpp b/sming/sming/network/MqttClient.cpp index 941aa85..1701a2a 100644 --- a/sming/sming/network/MqttClient.cpp +++ b/sming/sming/network/MqttClient.cpp @@ -310,7 +310,9 @@ err_t MqttClient::onReceive(pbuf *buf) void MqttClient::onReadyToSendData(TcpConnectionEvent sourceEvent) { - // Send PINGREQ every PingRepeatTime , if there is no outgoing traffic + + // Send PINGREQ every PingRepeatTime time, if there is no outgoing traffic + // PingRepeatTime should be <= keepAlive if (lastMessage && (millis() - lastMessage >= PingRepeatTime*1000)) { mqtt_ping(&broker);