Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
1c2ee75a
Commit
1c2ee75a
authored
Apr 03, 2015
by
funshine
Browse files
fix mqtt, do a format when wrong flash size is detected
parent
32e062f5
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
1c2ee75a
...
@@ -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
reconnec
t.
m
:
close
();
-- if auto-reconnect =
=
1, will
disable auto-reconnect and then disconnect from hos
t.
-- you can call m:connect again
-- you can call m:connect again
```
```
...
...
app/include/user_version.h
View file @
1c2ee75a
...
@@ -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 20150
331
"
#define BUILD_DATE "build 20150
403
"
#endif
/* __USER_VERSION_H__ */
#endif
/* __USER_VERSION_H__ */
app/modules/mqtt.c
View file @
1c2ee75a
This diff is collapsed.
Click to expand it.
app/platform/flash_fs.h
View file @
1c2ee75a
...
@@ -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
...
...
app/spiffs/spiffs.c
View file @
1c2ee75a
...
@@ -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
my
spiffs_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
();
my
spiffs_mount
();
return
1
;
return
1
;
}
}
...
...
app/spiffs/spiffs.h
View file @
1c2ee75a
...
@@ -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
);
...
...
app/user/Makefile
View file @
1c2ee75a
...
@@ -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
app/user/user_main.c
View file @
1c2ee75a
...
@@ -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
(
"
\n
i*** 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 )
spif
fs_mount
();
fs_mount
();
// test_spiffs();
// test_spiffs();
#endif
#endif
// endpoint_setup();
// endpoint_setup();
...
...
examples/fragment.lua
View file @
1c2ee75a
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment