Commit 1c2ee75a authored by funshine's avatar funshine
Browse files

fix mqtt, do a format when wrong flash size is detected

parent 32e062f5
...@@ -243,7 +243,7 @@ m:subscribe("/topic",0, function(conn) print("subscribe success") end) ...@@ -243,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.
...@@ -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();
......
...@@ -460,3 +460,15 @@ m:publish("/topic1","hello3",0,0) m:publish("/topic1","hello2",2,0) ...@@ -460,3 +460,15 @@ m:publish("/topic1","hello3",0,0) m:publish("/topic1","hello2",2,0)
m:subscribe("/topic2",2,function(m) print("sub done") end) m:subscribe("/topic2",2,function(m) print("sub done") end)
m:publish("/topic2","hello3",0,0) m:publish("/topic2","hello2",2,0) 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