Commit dceed526 authored by Vowstar's avatar Vowstar
Browse files

Merge pull request #470 from nodemcu/dev096

* Update SDK to 0.9.6
* Fix some bugs
* Update examples
* Add crypto module by @creationix 
parents 0ad57470 b0a4e4d3
......@@ -42,7 +42,7 @@ The small 4KB sectors allow for greater flexibility in applications th
********************/
void spiffs_mount() {
void myspiffs_mount() {
spiffs_config cfg;
cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL );
cfg.phys_addr += 0x3000;
......@@ -69,6 +69,10 @@ void spiffs_mount() {
NODE_DBG("mount res: %i\n", res);
}
void myspiffs_unmount() {
SPIFFS_unmount(&fs);
}
// FS formatting function
// Returns 1 if OK, 0 for error
int myspiffs_format( void )
......@@ -85,7 +89,7 @@ int myspiffs_format( void )
while( sect_first <= sect_last )
if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR )
return 0;
spiffs_mount();
myspiffs_mount();
return 1;
}
......
......@@ -477,6 +477,8 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages);
#if SPIFFS_CACHE
#endif
void myspiffs_mount();
void myspiffs_unmount();
int myspiffs_open(const char *name, int flags);
int myspiffs_close( int fd );
size_t myspiffs_write( int fd, const void* ptr, size_t len );
......
......@@ -395,13 +395,11 @@ typedef struct __attribute(( packed )) {
// common page header
spiffs_page_header p_hdr;
// alignment
u8_t _align[4 - (sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3)];
u8_t _align[4 - ((sizeof(spiffs_page_header)+sizeof(spiffs_obj_type)+SPIFFS_OBJ_NAME_LEN)&3)==0 ? 4 : ((sizeof(spiffs_page_header)+sizeof(spiffs_obj_type)+SPIFFS_OBJ_NAME_LEN)&3)];
// size of object
u32_t size;
// type of object
spiffs_obj_type type;
// alignment2
u8_t _align2[4 - (sizeof(spiffs_obj_type)&3)==0 ? 4 : (sizeof(spiffs_obj_type)&3)];
// name of object
u8_t name[SPIFFS_OBJ_NAME_LEN];
} spiffs_page_object_ix_header;
......
......@@ -44,6 +44,7 @@ INCLUDES += -I ../libc
INCLUDES += -I ../platform
INCLUDES += -I ../lua
INCLUDES += -I ../wofs
INCLUDES += -I ../spiffs
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
......@@ -14,8 +14,7 @@
#include "c_stdlib.h"
#include "c_stdio.h"
#include "romfs.h"
#include "flash_fs.h"
#include "user_interface.h"
#include "ets_sys.h"
......@@ -44,7 +43,6 @@ void task_init(void){
system_os_task(task_lua, USER_TASK_PRIO_0, taskQueue, TASK_QUEUE_LEN);
}
extern void spiffs_mount();
// extern void test_spiffs();
// extern int test_romfs();
......@@ -70,6 +68,15 @@ void nodemcu_init(void)
flash_init_data_default();
// Flash blank data at FLASHSIZE - 0x02000 Byte.
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)
......@@ -94,7 +101,7 @@ void nodemcu_init(void)
// test_romfs();
#elif defined ( BUILD_SPIFFS )
spiffs_mount();
fs_mount();
// test_spiffs();
#endif
// endpoint_setup();
......
......@@ -381,3 +381,141 @@ function TestDNSLeak()
tmr.alarm(1, 3000, 0, function() print("hack socket close, MEM: "..node.heap()) c:close() end) -- socket timeout hack
print("MEM: "..node.heap())
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)
-- serout( pin, firstLevel, delay_table, [repeatNum] )
gpio.mode(1,gpio.OUTPUT,gpio.PULLUP)
gpio.serout(1,1,{30,30,60,60,30,30}) -- serial one byte, b10110010
gpio.serout(1,1,{30,70},8) -- serial 30% pwm 10k, lasts 8 cycles
gpio.serout(1,1,{3,7},8) -- serial 30% pwm 100k, lasts 8 cycles
gpio.serout(1,1,{0,0},8) -- serial 50% pwm as fast as possible, lasts 8 cycles
gpio.mode(1,gpio.OUTPUT,gpio.PULLUP)
gpio.serout(1,0,{20,10,10,20,10,10,10,100}) -- sim uart one byte 0x5A at about 100kbps
gpio.serout(1,1,{8,18},8) -- serial 30% pwm 38k, lasts 8 cycles
-- Lua: mqtt.Client(clientid, keepalive, user, pass)
-- test with cloudmqtt.com
m_dis={}
function dispatch(m,t,pl)
if pl~=nil and m_dis[t] then
m_dis[t](pl)
end
end
function topic1func(pl)
print("get1: "..pl)
end
function topic2func(pl)
print("get2: "..pl)
end
m_dis["/topic1"]=topic1func
m_dis["/topic2"]=topic2func
m=mqtt.Client("nodemcu1",60,"test","test123")
m:on("connect",function(m)
print("connection "..node.heap())
m:subscribe("/topic1",0,function(m) print("sub done") end)
m:subscribe("/topic2",0,function(m) print("sub done") end)
m:publish("/topic1","hello",0,0) m:publish("/topic2","world",0,0)
end )
m:on("offline", function(conn)
print("disconnect to broker...")
print(node.heap())
end)
m:on("message",dispatch )
m:connect("m11.cloudmqtt.com",11214,0,1)
-- Lua: mqtt:connect( host, port, secure, auto_reconnect, function(client) )
tmr.alarm(0,10000,1,function() local pl = "time: "..tmr.time()
m:publish("/topic1",pl,0,0)
end)
--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")
......@@ -53,6 +53,7 @@ typedef struct _esp_tcp {
espconn_connect_callback connect_callback;
espconn_reconnect_callback reconnect_callback;
espconn_connect_callback disconnect_callback;
espconn_connect_callback write_finish_fn;
} esp_tcp;
typedef struct _esp_udp {
......@@ -90,8 +91,10 @@ struct espconn {
};
enum espconn_option{
ESPCONN_REUSEADDR = 1,
ESPCONN_NODELAY,
ESPCONN_START = 0x00,
ESPCONN_REUSEADDR = 0x01,
ESPCONN_NODELAY = 0x02,
ESPCONN_COPY = 0x04,
ESPCONN_END
};
......@@ -209,6 +212,18 @@ sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_in
sint8 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb);
/******************************************************************************
* FunctionName : espconn_regist_sentcb
* Description : Used to specify the function that should be called when data
* has been successfully delivered to the remote host.
* Parameters : espconn -- espconn to set the sent callback
* sent_cb -- sent callback function to call for this espconn
* when data is successfully sent
* Returns : none
*******************************************************************************/
sint8 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn);
/******************************************************************************
* FunctionName : espconn_sent
* Description : sent data for client or server
......
......@@ -89,6 +89,7 @@ bool system_rtc_mem_write(uint8 des_addr, const void *src_addr, uint16 save_size
void system_uart_swap(void);
uint16 system_adc_read(void);
uint16 system_get_vdd33(void);
const char *system_get_sdk_version(void);
......@@ -97,6 +98,7 @@ const char *system_get_sdk_version(void);
#define SOFTAP_MODE 0x02
#define STATIONAP_MODE 0x03
typedef enum _auth_mode {
AUTH_OPEN = 0,
AUTH_WEP,
......@@ -240,6 +242,10 @@ typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len);
void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
#define PHY_MODE_B 0x01
#define PHY_MODE_G 0x02
#define PHY_MODE_N 0x03
enum phy_mode {
PHY_MODE_11B = 1,
PHY_MODE_11G = 2,
......
......@@ -5,7 +5,7 @@ MEMORY
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x5A000
irom0_0_seg : org = 0x40210000, len = 0x60000
}
PHDRS
......@@ -71,7 +71,6 @@ SECTIONS
_irom0_text_start = ABSOLUTE(.);
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
*(.literal.* .text.*)
*(.rodata2.text)
/* put font and progmem data into irom0 */
*(.u8g_progmem.*)
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
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