Commit 2859286e authored by HuangRui's avatar HuangRui
Browse files
parents fc3ad901 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.
...@@ -237,7 +243,7 @@ m:subscribe("/topic",0, function(conn) print("subscribe success") end) ...@@ -237,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(); -- if auto-reconnect = 1, will reconnect. 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
``` ```
......
...@@ -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 20150331" #define BUILD_DATE "build 20150403"
#endif /* __USER_VERSION_H__ */ #endif /* __USER_VERSION_H__ */
This diff is collapsed.
...@@ -58,3 +58,25 @@ msg_queue_t * msg_dequeue(msg_queue_t **head){ ...@@ -58,3 +58,25 @@ msg_queue_t * msg_dequeue(msg_queue_t **head){
node->next = NULL; node->next = NULL;
return node; 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;
}
...@@ -18,6 +18,8 @@ typedef struct msg_queue_t { ...@@ -18,6 +18,8 @@ typedef struct 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); 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); void msg_destroy(msg_queue_t *node);
msg_queue_t * msg_dequeue(msg_queue_t **head); 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 #ifdef __cplusplus
} }
......
...@@ -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();
......
...@@ -418,7 +418,7 @@ m:publish("/topic1","hello",0,0) ...@@ -418,7 +418,7 @@ m:publish("/topic1","hello",0,0)
m:publish("/topic3","hello",0,0) m:publish("/topic4","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","hello1",0,0) m:publish("/topic2","hello2",0,0)
m:publish("/topic1","hello",1,0) m:publish("/topic1","hello",1,0)
m:subscribe("/topic3",2,function(m) print("sub done") end) m:subscribe("/topic3",0,function(m) print("sub done") end)
m:publish("/topic3","hello3",2,0) m:publish("/topic3","hello3",2,0)
m=mqtt.Client() m=mqtt.Client()
...@@ -450,3 +450,25 @@ end) ...@@ -450,3 +450,25 @@ end)
m:connect("192.168.18.88",1883) m:connect("192.168.18.88",1883)
m:close() 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)
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