"components/user/user_main.c" did not exist on "3c6ebea059c00773a9123afc1dd235cd6fa6c2b5"
Commit ea64cc75 authored by AllAboutEE's avatar AllAboutEE
Browse files

Merge branch 'dev' of https://github.com/nodemcu/nodemcu-firmware into dev

parents 1c267dfa 1c2ee75a
...@@ -36,6 +36,12 @@ Tencent QQ group: 309957875<br /> ...@@ -36,6 +36,12 @@ Tencent QQ group: 309957875<br />
- cross compiler (done) - cross compiler (done)
# Change log # Change log
2015-03-31<br />
polish mqtt module, add queue for mqtt module.<br />
add reconnect option to mqtt.connect api, :connect( host, port, secure, auto_reconnect, function(client) )<br />
move node.readvdd33 to adc.readvdd33.<br />
tools/esptool.py supported NodeMCU devkit automatic flash.
2015-03-18<br /> 2015-03-18<br />
update u8glib.<br /> update u8glib.<br />
merge everything to master. merge everything to master.
...@@ -225,8 +231,10 @@ m:on("message", function(conn, topic, data) ...@@ -225,8 +231,10 @@ m:on("message", function(conn, topic, data)
end end
end) end)
-- for secure: m:connect("192.168.11.118", 1880, 1) -- m:connect( host, port, secure, auto_reconnect, function(client) )
m:connect("192.168.11.118", 1880, 0, function(conn) print("connected") end) -- for secure: m:connect("192.168.11.118", 1880, 1, 0)
-- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1)
m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end)
-- subscribe topic with qos = 0 -- subscribe topic with qos = 0
m:subscribe("/topic",0, function(conn) print("subscribe success") end) m:subscribe("/topic",0, function(conn) print("subscribe success") end)
...@@ -235,7 +243,7 @@ m:subscribe("/topic",0, function(conn) print("subscribe success") end) ...@@ -235,7 +243,7 @@ m:subscribe("/topic",0, function(conn) print("subscribe success") end)
-- publish a message with data = hello, QoS = 0, retain = 0 -- publish a message with data = hello, QoS = 0, retain = 0
m:publish("/topic","hello",0,0, function(conn) print("sent") end) m:publish("/topic","hello",0,0, function(conn) print("sent") end)
m:close(); m:close(); -- if auto-reconnect == 1, will disable auto-reconnect and then disconnect from host.
-- you can call m:connect again -- you can call m:connect again
``` ```
......
...@@ -46,7 +46,7 @@ int strbuf_init(strbuf_t *s, int len) ...@@ -46,7 +46,7 @@ int strbuf_init(strbuf_t *s, int len)
s->reallocs = 0; s->reallocs = 0;
s->debug = 0; s->debug = 0;
s->buf = c_malloc(size); s->buf = (char *)c_malloc(size);
if (!s->buf){ if (!s->buf){
NODE_ERR("not enough memory\n"); NODE_ERR("not enough memory\n");
return -1; return -1;
...@@ -60,7 +60,7 @@ strbuf_t *strbuf_new(int len) ...@@ -60,7 +60,7 @@ strbuf_t *strbuf_new(int len)
{ {
strbuf_t *s; strbuf_t *s;
s = c_malloc(sizeof(strbuf_t)); s = (strbuf_t *)c_malloc(sizeof(strbuf_t));
if (!s){ if (!s){
NODE_ERR("not enough memory\n"); NODE_ERR("not enough memory\n");
return NULL; return NULL;
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
#define NODE_VERSION_INTERNAL 0U #define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 0.9.5" #define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 20150318" #define BUILD_DATE "build 20150403"
#endif /* __USER_VERSION_H__ */ #endif /* __USER_VERSION_H__ */
...@@ -47,9 +47,9 @@ extern int c_stderr; ...@@ -47,9 +47,9 @@ extern int c_stderr;
#define SEEK_END 2 /* set file offset to EOF plus offset */ #define SEEK_END 2 /* set file offset to EOF plus offset */
#endif #endif
#define c_malloc os_malloc // #define c_malloc os_malloc
#define c_zalloc os_zalloc // #define c_zalloc os_zalloc
#define c_free os_free // #define c_free os_free
extern void output_redirect(const char *str); extern void output_redirect(const char *str);
#define c_puts output_redirect #define c_puts output_redirect
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
#define os_realloc(p, s) mem_realloc((p), (s)) #define os_realloc(p, s) mem_realloc((p), (s))
#endif #endif
// #define c_free os_free #define c_free os_free
// #define c_malloc os_malloc #define c_malloc os_malloc
// #define c_zalloc os_zalloc #define c_zalloc os_zalloc
#define c_realloc os_realloc #define c_realloc os_realloc
#define c_abs abs #define c_abs abs
...@@ -47,9 +47,9 @@ ...@@ -47,9 +47,9 @@
// c_getenv() get env "LUA_INIT" string for lua initialization. // c_getenv() get env "LUA_INIT" string for lua initialization.
const char *c_getenv(const char *__string); const char *c_getenv(const char *__string);
void *c_malloc(size_t __size); // void *c_malloc(size_t __size);
void *c_zalloc(size_t __size); // void *c_zalloc(size_t __size);
void c_free(void *); // void c_free(void *);
// int c_rand(void); // int c_rand(void);
// void c_srand(unsigned int __seed); // void c_srand(unsigned int __seed);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "lrotable.h" #include "lrotable.h"
#include "c_types.h" #include "c_types.h"
#include "user_interface.h"
// Lua: read(id) , return system adc // Lua: read(id) , return system adc
static int adc_sample( lua_State* L ) static int adc_sample( lua_State* L )
...@@ -19,12 +20,33 @@ static int adc_sample( lua_State* L ) ...@@ -19,12 +20,33 @@ static int adc_sample( lua_State* L )
return 1; return 1;
} }
// Lua: readvdd33()
static int adc_readvdd33( lua_State* L )
{
uint32_t vdd33 = 0;
if(STATION_MODE == wifi_get_opmode())
{
// Bug fix
wifi_set_opmode( STATIONAP_MODE );
vdd33 = readvdd33();
wifi_set_opmode( STATION_MODE );
}
else
{
vdd33 = readvdd33();
}
lua_pushinteger(L, vdd33);
return 1;
}
// Module function map // Module function map
#define MIN_OPT_LEVEL 2 #define MIN_OPT_LEVEL 2
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE adc_map[] = const LUA_REG_TYPE adc_map[] =
{ {
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
#endif #endif
......
This diff is collapsed.
...@@ -100,13 +100,15 @@ static int node_chipid( lua_State* L ) ...@@ -100,13 +100,15 @@ static int node_chipid( lua_State* L )
lua_pushinteger(L, id); lua_pushinteger(L, id);
return 1; return 1;
} }
// deprecated, moved to adc module
// Lua: readvdd33() // Lua: readvdd33()
static int node_readvdd33( lua_State* L ) // static int node_readvdd33( lua_State* L )
{ // {
uint32_t vdd33 = readvdd33(); // uint32_t vdd33 = readvdd33();
lua_pushinteger(L, vdd33); // lua_pushinteger(L, vdd33);
return 1; // return 1;
} // }
// Lua: flashid() // Lua: flashid()
static int node_flashid( lua_State* L ) static int node_flashid( lua_State* L )
...@@ -430,7 +432,8 @@ const LUA_REG_TYPE node_map[] = ...@@ -430,7 +432,8 @@ const LUA_REG_TYPE node_map[] =
#endif #endif
{ LSTRKEY( "input" ), LFUNCVAL( node_input ) }, { LSTRKEY( "input" ), LFUNCVAL( node_input ) },
{ LSTRKEY( "output" ), LFUNCVAL( node_output ) }, { LSTRKEY( "output" ), LFUNCVAL( node_output ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) }, // Moved to adc module, use adc.readvdd33()
// { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
{ LSTRKEY( "compile" ), LFUNCVAL( node_compile) }, { LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
{ LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) }, { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) },
{ LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) }, { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) },
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* *
*/ */
#include <string.h> #include "c_string.h"
#include "mqtt_msg.h" #include "mqtt_msg.h"
#define MQTT_MAX_FIXED_HEADER_SIZE 3 #define MQTT_MAX_FIXED_HEADER_SIZE 3
...@@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int ...@@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int
connection->buffer[connection->message.length++] = len >> 8; connection->buffer[connection->message.length++] = len >> 8;
connection->buffer[connection->message.length++] = len & 0xff; connection->buffer[connection->message.length++] = len & 0xff;
memcpy(connection->buffer + connection->message.length, string, len); c_memcpy(connection->buffer + connection->message.length, string, len);
connection->message.length += len; connection->message.length += len;
return len + 2; return len + 2;
...@@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int ...@@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int
void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length) void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length)
{ {
memset(connection, 0, sizeof(connection)); c_memset(connection, 0, sizeof(connection));
connection->buffer = buffer; connection->buffer = buffer;
connection->buffer_length = buffer_length; connection->buffer_length = buffer_length;
} }
...@@ -294,7 +294,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf ...@@ -294,7 +294,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
variable_header->lengthMsb = 0; variable_header->lengthMsb = 0;
variable_header->lengthLsb = 4; variable_header->lengthLsb = 4;
memcpy(variable_header->magic, "MQTT", 4); c_memcpy(variable_header->magic, "MQTT", 4);
variable_header->version = 4; variable_header->version = 4;
variable_header->flags = 0; variable_header->flags = 0;
variable_header->keepaliveMsb = info->keepalive >> 8; variable_header->keepaliveMsb = info->keepalive >> 8;
...@@ -305,7 +305,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf ...@@ -305,7 +305,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->client_id != NULL && info->client_id[0] != '\0') if(info->client_id != NULL && info->client_id[0] != '\0')
{ {
if(append_string(connection, info->client_id, strlen(info->client_id)) < 0) if(append_string(connection, info->client_id, c_strlen(info->client_id)) < 0)
return fail_message(connection); return fail_message(connection);
} }
else else
...@@ -313,10 +313,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf ...@@ -313,10 +313,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->will_topic != NULL && info->will_topic[0] != '\0') if(info->will_topic != NULL && info->will_topic[0] != '\0')
{ {
if(append_string(connection, info->will_topic, strlen(info->will_topic)) < 0) if(append_string(connection, info->will_topic, c_strlen(info->will_topic)) < 0)
return fail_message(connection); return fail_message(connection);
if(append_string(connection, info->will_message, strlen(info->will_message)) < 0) if(append_string(connection, info->will_message, c_strlen(info->will_message)) < 0)
return fail_message(connection); return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_WILL; variable_header->flags |= MQTT_CONNECT_FLAG_WILL;
...@@ -327,7 +327,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf ...@@ -327,7 +327,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->username != NULL && info->username[0] != '\0') if(info->username != NULL && info->username[0] != '\0')
{ {
if(append_string(connection, info->username, strlen(info->username)) < 0) if(append_string(connection, info->username, c_strlen(info->username)) < 0)
return fail_message(connection); return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME; variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME;
...@@ -335,7 +335,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf ...@@ -335,7 +335,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->password != NULL && info->password[0] != '\0') if(info->password != NULL && info->password[0] != '\0')
{ {
if(append_string(connection, info->password, strlen(info->password)) < 0) if(append_string(connection, info->password, c_strlen(info->password)) < 0)
return fail_message(connection); return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD; variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD;
...@@ -351,7 +351,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi ...@@ -351,7 +351,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if(topic == NULL || topic[0] == '\0') if(topic == NULL || topic[0] == '\0')
return fail_message(connection); return fail_message(connection);
if(append_string(connection, topic, strlen(topic)) < 0) if(append_string(connection, topic, c_strlen(topic)) < 0)
return fail_message(connection); return fail_message(connection);
if(qos > 0) if(qos > 0)
...@@ -364,7 +364,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi ...@@ -364,7 +364,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if(connection->message.length + data_length > connection->buffer_length) if(connection->message.length + data_length > connection->buffer_length)
return fail_message(connection); return fail_message(connection);
memcpy(connection->buffer + connection->message.length, data, data_length); c_memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length; connection->message.length += data_length;
return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain); return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);
...@@ -412,7 +412,7 @@ mqtt_message_t* mqtt_msg_subscribe(mqtt_connection_t* connection, const char* to ...@@ -412,7 +412,7 @@ mqtt_message_t* mqtt_msg_subscribe(mqtt_connection_t* connection, const char* to
if((*message_id = append_message_id(connection, 0)) == 0) if((*message_id = append_message_id(connection, 0)) == 0)
return fail_message(connection); return fail_message(connection);
if(append_string(connection, topic, strlen(topic)) < 0) if(append_string(connection, topic, c_strlen(topic)) < 0)
return fail_message(connection); return fail_message(connection);
if(connection->message.length + 1 > connection->buffer_length) if(connection->message.length + 1 > connection->buffer_length)
...@@ -432,7 +432,7 @@ mqtt_message_t* mqtt_msg_unsubscribe(mqtt_connection_t* connection, const char* ...@@ -432,7 +432,7 @@ mqtt_message_t* mqtt_msg_unsubscribe(mqtt_connection_t* connection, const char*
if((*message_id = append_message_id(connection, 0)) == 0) if((*message_id = append_message_id(connection, 0)) == 0)
return fail_message(connection); return fail_message(connection);
if(append_string(connection, topic, strlen(topic)) < 0) if(append_string(connection, topic, c_strlen(topic)) < 0)
return fail_message(connection); return fail_message(connection);
return fini_message(connection, MQTT_MSG_TYPE_SUBSCRIBE, 0, 1, 0); return fini_message(connection, MQTT_MSG_TYPE_SUBSCRIBE, 0, 1, 0);
......
#include "c_string.h"
#include "c_stdlib.h"
#include "c_stdio.h"
#include "msg_queue.h"
msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos){
if(!head){
return NULL;
}
if (!msg || !msg->data || msg->length == 0){
NODE_DBG("empty message\n");
return NULL;
}
msg_queue_t *node = (msg_queue_t *)c_zalloc(sizeof(msg_queue_t));
if(!node){
NODE_DBG("not enough memory\n");
return NULL;
}
node->msg.data = (uint8_t *)c_zalloc(msg->length);
if(!node->msg.data){
NODE_DBG("not enough memory\n");
c_free(node);
return NULL;
}
c_memcpy(node->msg.data, msg->data, msg->length);
node->msg.length = msg->length;
node->next = NULL;
node->msg_id = msg_id;
node->msg_type = msg_type;
node->publish_qos = publish_qos;
msg_queue_t *tail = *head;
if(tail){
while(tail->next!=NULL) tail = tail->next;
tail->next = node;
} else {
*head = node;
}
return node;
}
void msg_destroy(msg_queue_t *node){
if(!node) return;
if(node->msg.data){
c_free(node->msg.data);
node->msg.data = NULL;
}
c_free(node);
}
msg_queue_t * msg_dequeue(msg_queue_t **head){
if(!head || !*head){
return NULL;
}
msg_queue_t *node = *head; // fetch head.
*head = node->next; // update head.
node->next = NULL;
return node;
}
msg_queue_t * msg_peek(msg_queue_t **head){
if(!head || !*head){
return NULL;
}
return *head; // fetch head.
}
int msg_size(msg_queue_t **head){
if(!head || !*head){
return 0;
}
int i = 1;
msg_queue_t *tail = *head;
if(tail){
while(tail->next!=NULL){
tail = tail->next;
i++;
}
}
return i;
}
#ifndef _MSG_QUEUE_H
#define _MSG_QUEUE_H 1
#include "mqtt_msg.h"
#ifdef __cplusplus
extern "C" {
#endif
struct msg_queue_t;
typedef struct msg_queue_t {
struct msg_queue_t *next;
mqtt_message_t msg;
uint16_t msg_id;
int msg_type;
int publish_qos;
} msg_queue_t;
msg_queue_t * msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos);
void msg_destroy(msg_queue_t *node);
msg_queue_t * msg_dequeue(msg_queue_t **head);
msg_queue_t * msg_peek(msg_queue_t **head);
int msg_size(msg_queue_t **head);
#ifdef __cplusplus
}
#endif
#endif
...@@ -321,7 +321,7 @@ bool flash_init_data_written(void) ...@@ -321,7 +321,7 @@ bool flash_init_data_written(void)
// FLASH SEC - 4 // FLASH SEC - 4
uint32_t data[2] ICACHE_STORE_ATTR; uint32_t data[2] ICACHE_STORE_ATTR;
#if defined(FLASH_SAFE_API) #if defined(FLASH_SAFE_API)
if (SPI_FLASH_RESULT_OK == flash_safe_read((flash_rom_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)data, sizeof(data))) if (SPI_FLASH_RESULT_OK == flash_safe_read((flash_safe_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)data, sizeof(data)))
#else #else
if (SPI_FLASH_RESULT_OK == spi_flash_read((flash_rom_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)data, sizeof(data))) if (SPI_FLASH_RESULT_OK == spi_flash_read((flash_rom_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, (uint32 *)data, sizeof(data)))
#endif // defined(FLASH_SAFE_API) #endif // defined(FLASH_SAFE_API)
...@@ -369,8 +369,8 @@ bool flash_init_data_blank(void) ...@@ -369,8 +369,8 @@ bool flash_init_data_blank(void)
// It will init system config to blank! // It will init system config to blank!
bool result = false; bool result = false;
#if defined(FLASH_SAFE_API) #if defined(FLASH_SAFE_API)
if ((SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_rom_get_sec_num() - 2))) && if ((SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 2))) &&
(SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_rom_get_sec_num() - 1)))) (SPI_FLASH_RESULT_OK == flash_safe_erase_sector((flash_safe_get_sec_num() - 1))))
#else #else
if ((SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 2))) && if ((SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 2))) &&
(SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 1)))) (SPI_FLASH_RESULT_OK == spi_flash_erase_sector((flash_rom_get_sec_num() - 1))))
......
...@@ -71,6 +71,9 @@ ...@@ -71,6 +71,9 @@
#define fs_rename myspiffs_rename #define fs_rename myspiffs_rename
#define fs_size myspiffs_size #define fs_size myspiffs_size
#define fs_mount myspiffs_mount
#define fs_unmount myspiffs_unmount
#define FS_NAME_MAX_LENGTH SPIFFS_OBJ_NAME_LEN #define FS_NAME_MAX_LENGTH SPIFFS_OBJ_NAME_LEN
#endif #endif
......
...@@ -42,7 +42,7 @@ The small 4KB sectors allow for greater flexibility in applications th ...@@ -42,7 +42,7 @@ The small 4KB sectors allow for greater flexibility in applications th
********************/ ********************/
void spiffs_mount() { void myspiffs_mount() {
spiffs_config cfg; spiffs_config cfg;
cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ); cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL );
cfg.phys_addr += 0x3000; cfg.phys_addr += 0x3000;
...@@ -69,6 +69,10 @@ void spiffs_mount() { ...@@ -69,6 +69,10 @@ void spiffs_mount() {
NODE_DBG("mount res: %i\n", res); NODE_DBG("mount res: %i\n", res);
} }
void myspiffs_unmount() {
SPIFFS_unmount(&fs);
}
// FS formatting function // FS formatting function
// Returns 1 if OK, 0 for error // Returns 1 if OK, 0 for error
int myspiffs_format( void ) int myspiffs_format( void )
...@@ -85,7 +89,7 @@ int myspiffs_format( void ) ...@@ -85,7 +89,7 @@ int myspiffs_format( void )
while( sect_first <= sect_last ) while( sect_first <= sect_last )
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
return 0; return 0;
spiffs_mount(); myspiffs_mount();
return 1; return 1;
} }
......
...@@ -477,6 +477,8 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages); ...@@ -477,6 +477,8 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages);
#if SPIFFS_CACHE #if SPIFFS_CACHE
#endif #endif
void myspiffs_mount();
void myspiffs_unmount();
int myspiffs_open(const char *name, int flags); int myspiffs_open(const char *name, int flags);
int myspiffs_close( int fd ); int myspiffs_close( int fd );
size_t myspiffs_write( int fd, const void* ptr, size_t len ); size_t myspiffs_write( int fd, const void* ptr, size_t len );
......
...@@ -44,6 +44,7 @@ INCLUDES += -I ../libc ...@@ -44,6 +44,7 @@ INCLUDES += -I ../libc
INCLUDES += -I ../platform INCLUDES += -I ../platform
INCLUDES += -I ../lua INCLUDES += -I ../lua
INCLUDES += -I ../wofs INCLUDES += -I ../wofs
INCLUDES += -I ../spiffs
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_stdio.h" #include "c_stdio.h"
#include "romfs.h" #include "flash_fs.h"
#include "user_interface.h" #include "user_interface.h"
#include "ets_sys.h" #include "ets_sys.h"
...@@ -44,7 +43,6 @@ void task_init(void){ ...@@ -44,7 +43,6 @@ void task_init(void){
system_os_task(task_lua, USER_TASK_PRIO_0, taskQueue, TASK_QUEUE_LEN); system_os_task(task_lua, USER_TASK_PRIO_0, taskQueue, TASK_QUEUE_LEN);
} }
extern void spiffs_mount();
// extern void test_spiffs(); // extern void test_spiffs();
// extern int test_romfs(); // extern int test_romfs();
...@@ -69,7 +67,16 @@ void nodemcu_init(void) ...@@ -69,7 +67,16 @@ void nodemcu_init(void)
// Flash init data at FLASHSIZE - 0x04000 Byte. // Flash init data at FLASHSIZE - 0x04000 Byte.
flash_init_data_default(); flash_init_data_default();
// Flash blank data at FLASHSIZE - 0x02000 Byte. // Flash blank data at FLASHSIZE - 0x02000 Byte.
flash_init_data_blank(); flash_init_data_blank();
if( !fs_format() )
{
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
}
else{
NODE_ERR( "format done.\n" );
}
fs_unmount(); // mounted by format.
} }
#endif // defined(FLASH_SAFE_API) #endif // defined(FLASH_SAFE_API)
...@@ -94,7 +101,7 @@ void nodemcu_init(void) ...@@ -94,7 +101,7 @@ void nodemcu_init(void)
// test_romfs(); // test_romfs();
#elif defined ( BUILD_SPIFFS ) #elif defined ( BUILD_SPIFFS )
spiffs_mount(); fs_mount();
// test_spiffs(); // test_spiffs();
#endif #endif
// endpoint_setup(); // endpoint_setup();
......
...@@ -381,3 +381,94 @@ function TestDNSLeak() ...@@ -381,3 +381,94 @@ function TestDNSLeak()
tmr.alarm(1, 3000, 0, function() print("hack socket close, MEM: "..node.heap()) c:close() end) -- socket timeout hack tmr.alarm(1, 3000, 0, function() print("hack socket close, MEM: "..node.heap()) c:close() end) -- socket timeout hack
print("MEM: "..node.heap()) print("MEM: "..node.heap())
end end
v="abc%0D%0Adef"
print(string.gsub(v, "%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end))
function ex(x) string.find("abc%0Ddef","bc") return 's' end
string.gsub("abc%0Ddef", "%%(%x%x)", ex)
function ex(x) string.char(35) return 's' end
string.gsub("abc%0Ddef", "%%(%x%x)", ex) print("hello")
function ex(x) string.lower('Ab') return 's' end
string.gsub("abc%0Ddef", "%%(%x%x)", ex) print("hello")
v="abc%0D%0Adef"
pcall(function() print(string.gsub(v, "%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end)) end)
mosca -v | bunyan
m=mqtt.Client()
m:connect("192.168.18.88",1883)
topic={}
topic["/topic1"]=0
topic["/topic2"]=0
m:subscribe(topic,function(m) print("sub done") end)
m:on("message",function(m,t,pl) print(t..":") if pl~=nil then print(pl) end end )
m:publish("/topic1","hello",0,0)
m:publish("/topic3","hello",0,0) m:publish("/topic4","hello",0,0)
m=mqtt.Client()
m:connect("192.168.18.88",1883)
m:subscribe("/topic1",0,function(m) print("sub done") end)
m:subscribe("/topic2",0,function(m) print("sub done") end)
m:on("message",function(m,t,pl) print(t..":") if pl~=nil then print(pl) end end )
m:publish("/topic1","hello",0,0)
m:publish("/topic3","hello",0,0) m:publish("/topic4","hello",0,0)
m:publish("/topic1","hello1",0,0) m:publish("/topic2","hello2",0,0)
m:publish("/topic1","hello",1,0)
m:subscribe("/topic3",0,function(m) print("sub done") end)
m:publish("/topic3","hello3",2,0)
m=mqtt.Client()
m:connect("192.168.18.88",1883, function(con) print("connected hello") end)
m=mqtt.Client()
m:on("connect",function(m) print("connection") end )
m:connect("192.168.18.88",1883)
m:on("offline",function(m) print("disconnection") end )
m=mqtt.Client()
m:on("connect",function(m) print("connection "..node.heap()) end )
m:on("offline", function(conn)
if conn == nil then print("conn is nil") end
print("Reconnect to broker...")
print(node.heap())
conn:connect("192.168.18.88",1883,0,1)
end)
m:connect("192.168.18.88",1883,0,1)
m=mqtt.Client()
m:on("connect",function(m) print("connection "..node.heap()) end )
m:on("offline", function(conn)
if conn == nil then print("conn is nil") end
print("Reconnect to broker...")
print(node.heap())
conn:connect("192.168.18.88",1883)
end)
m:connect("192.168.18.88",1883)
m:close()
m=mqtt.Client()
m:connect("192.168.18.88",1883)
m:on("message",function(m,t,pl) print(t..":") if pl~=nil then print(pl) end end )
m:subscribe("/topic1",0,function(m) print("sub done") end)
m:publish("/topic1","hello3",2,0) m:publish("/topic1","hello2",2,0)
m:publish("/topic1","hello3",0,0) m:publish("/topic1","hello2",2,0)
m:subscribe("/topic2",2,function(m) print("sub done") end)
m:publish("/topic2","hello3",0,0) m:publish("/topic2","hello2",2,0)
m=mqtt.Client()
m:on("connect",function(m)
print("connection "..node.heap())
m:subscribe("/topic1",0,function(m) print("sub done") end)
m:publish("/topic1","hello3",0,0) m:publish("/topic1","hello2",2,0)
end )
m:on("offline", function(conn)
print("disconnect to broker...")
print(node.heap())
end)
m:connect("192.168.18.88",1883,0,1)
--init.lua, something like this
countdown = 3
tmr.alarm(0,1000,1,function()
print(countdown)
countdown = countdown-1
if countdown<1 then
tmr.stop(0)
countdown = nil
local s,err
if file.open("user.lc") then
file.close()
s,err = pcall(function() dofile("user.lc") end)
else
s,err = pcall(function() dofile("user.lua") end)
end
if not s then print(err) end
end
end)
print("hello NodeMCU")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment