Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
cf4cd8f4
Commit
cf4cd8f4
authored
Jan 26, 2015
by
HuangRui
Browse files
Merge branch 'master' of
https://github.com/nodemcu/nodemcu-firmware
into devfloat
parents
f3303d00
d5047d66
Changes
10
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
cf4cd8f4
...
@@ -30,7 +30,11 @@ ifeq ($(OS),Windows_NT)
...
@@ -30,7 +30,11 @@ ifeq ($(OS),Windows_NT)
OBJCOPY
=
xtensa-lx106-elf-objcopy
OBJCOPY
=
xtensa-lx106-elf-objcopy
endif
endif
FIRMWAREDIR
=
..
\\
bin
\\
FIRMWAREDIR
=
..
\\
bin
\\
ESPPORT
=
com1
ifndef
COMPORT
ESPPORT
=
com1
else
ESPPORT
=
$(COMPORT)
endif
ifeq
($(PROCESSOR_ARCHITECTURE),AMD64)
ifeq
($(PROCESSOR_ARCHITECTURE),AMD64)
# ->AMD64
# ->AMD64
endif
endif
...
@@ -40,7 +44,11 @@ ifeq ($(OS),Windows_NT)
...
@@ -40,7 +44,11 @@ ifeq ($(OS),Windows_NT)
else
else
# We are under other system, may be Linux. Assume using gcc.
# We are under other system, may be Linux. Assume using gcc.
# Can we use -fdata-sections?
# Can we use -fdata-sections?
ESPPORT
=
/dev/ttyUSB0
ifndef
COMPORT
ESPPORT
=
/dev/ttyUSB0
else
ESPPORT
=
$(COMPORT)
endif
CCFLAGS
+=
-Os
-ffunction-sections
-fno-jump-tables
CCFLAGS
+=
-Os
-ffunction-sections
-fno-jump-tables
AR
=
xtensa-lx106-elf-ar
AR
=
xtensa-lx106-elf-ar
CC
=
xtensa-lx106-elf-gcc
CC
=
xtensa-lx106-elf-gcc
...
...
app/modules/node.c
View file @
cf4cd8f4
...
@@ -53,6 +53,13 @@ static int node_chipid( lua_State* L )
...
@@ -53,6 +53,13 @@ static int node_chipid( lua_State* L )
lua_pushinteger
(
L
,
id
);
lua_pushinteger
(
L
,
id
);
return
1
;
return
1
;
}
}
// Lua: readvdd33()
static
int
node_readvdd33
(
lua_State
*
L
)
{
uint32_t
vdd33
=
readvdd33
();
lua_pushinteger
(
L
,
vdd33
);
return
1
;
}
// Lua: flashid()
// Lua: flashid()
static
int
node_flashid
(
lua_State
*
L
)
static
int
node_flashid
(
lua_State
*
L
)
...
@@ -287,6 +294,7 @@ const LUA_REG_TYPE node_map[] =
...
@@ -287,6 +294,7 @@ const LUA_REG_TYPE node_map[] =
{
LSTRKEY
(
"led"
),
LFUNCVAL
(
node_led
)
},
{
LSTRKEY
(
"led"
),
LFUNCVAL
(
node_led
)
},
{
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
)
},
#if LUA_OPTIMIZE_MEMORY > 0
#if LUA_OPTIMIZE_MEMORY > 0
#endif
#endif
...
...
include/user_interface.h
View file @
cf4cd8f4
/*
/*
* Copyright (C) 2013 -2014 Espressif System
* Copyright (C) 2013 -2014 Espressif System
*
*
*/
*/
#ifndef __USER_INTERFACE_H__
#ifndef __USER_INTERFACE_H__
#define __USER_INTERFACE_H__
#define __USER_INTERFACE_H__
#include "os_type.h"
#include "os_type.h"
#ifdef LWIP_OPEN_SRC
#ifdef LWIP_OPEN_SRC
#include "lwip/ip_addr.h"
#include "lwip/ip_addr.h"
#else
#else
#include "ip_addr.h"
#include "ip_addr.h"
#endif
#endif
#include "queue.h"
#include "queue.h"
#include "user_config.h"
#include "user_config.h"
#include "spi_flash.h"
#include "spi_flash.h"
#ifndef MAC2STR
#ifndef MAC2STR
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
#endif
#endif
enum
rst_reason
{
enum
rst_reason
{
DEFAULT_RST_FLAG
=
0
,
DEFAULT_RST_FLAG
=
0
,
WDT_RST_FLAG
=
1
,
WDT_RST_FLAG
=
1
,
EXP_RST_FLAG
=
2
EXP_RST_FLAG
=
2
};
};
struct
rst_info
{
struct
rst_info
{
uint32
flag
;
uint32
flag
;
uint32
exccause
;
uint32
exccause
;
uint32
epc1
;
uint32
epc1
;
uint32
epc2
;
uint32
epc2
;
uint32
epc3
;
uint32
epc3
;
uint32
excvaddr
;
uint32
excvaddr
;
uint32
depc
;
uint32
depc
;
};
};
#define UPGRADE_FW_BIN1 0x00
#define UPGRADE_FW_BIN1 0x00
#define UPGRADE_FW_BIN2 0x01
#define UPGRADE_FW_BIN2 0x01
void
system_restore
(
void
);
void
system_restore
(
void
);
void
system_restart
(
void
);
void
system_restart
(
void
);
bool
system_deep_sleep_set_option
(
uint8
option
);
bool
system_deep_sleep_set_option
(
uint8
option
);
void
system_deep_sleep
(
uint32
time_in_us
);
void
system_deep_sleep
(
uint32
time_in_us
);
uint8
system_upgrade_userbin_check
(
void
);
uint8
system_upgrade_userbin_check
(
void
);
void
system_upgrade_reboot
(
void
);
void
system_upgrade_reboot
(
void
);
uint8
system_upgrade_flag_check
();
uint8
system_upgrade_flag_check
();
void
system_upgrade_flag_set
(
uint8
flag
);
void
system_upgrade_flag_set
(
uint8
flag
);
void
system_timer_reinit
(
void
);
void
system_timer_reinit
(
void
);
uint32
system_get_time
(
void
);
uint32
system_get_time
(
void
);
/* user task's prio must be 0/1/2 !!!*/
/* user task's prio must be 0/1/2 !!!*/
enum
{
enum
{
USER_TASK_PRIO_0
=
0
,
USER_TASK_PRIO_0
=
0
,
USER_TASK_PRIO_1
,
USER_TASK_PRIO_1
,
USER_TASK_PRIO_2
,
USER_TASK_PRIO_2
,
USER_TASK_PRIO_MAX
USER_TASK_PRIO_MAX
};
};
bool
system_os_task
(
os_task_t
task
,
uint8
prio
,
os_event_t
*
queue
,
uint8
qlen
);
bool
system_os_task
(
os_task_t
task
,
uint8
prio
,
os_event_t
*
queue
,
uint8
qlen
);
bool
system_os_post
(
uint8
prio
,
os_signal_t
sig
,
os_param_t
par
);
bool
system_os_post
(
uint8
prio
,
os_signal_t
sig
,
os_param_t
par
);
void
system_print_meminfo
(
void
);
void
system_print_meminfo
(
void
);
uint32
system_get_free_heap_size
(
void
);
uint32
system_get_free_heap_size
(
void
);
void
system_set_os_print
(
uint8
onoff
);
void
system_set_os_print
(
uint8
onoff
);
uint8
system_get_os_print
();
uint8
system_get_os_print
();
uint64
system_mktime
(
uint32
year
,
uint32
mon
,
uint32
day
,
uint32
hour
,
uint32
min
,
uint32
sec
);
uint64
system_mktime
(
uint32
year
,
uint32
mon
,
uint32
day
,
uint32
hour
,
uint32
min
,
uint32
sec
);
uint32
system_get_chip_id
(
void
);
uint32
system_get_chip_id
(
void
);
typedef
void
(
*
init_done_cb_t
)(
void
);
typedef
void
(
*
init_done_cb_t
)(
void
);
void
system_init_done_cb
(
init_done_cb_t
cb
);
void
system_init_done_cb
(
init_done_cb_t
cb
);
uint32
system_rtc_clock_cali_proc
(
void
);
uint32
system_rtc_clock_cali_proc
(
void
);
uint32
system_get_rtc_time
(
void
);
uint32
system_get_rtc_time
(
void
);
bool
system_rtc_mem_read
(
uint8
src_addr
,
void
*
des_addr
,
uint16
load_size
);
bool
system_rtc_mem_read
(
uint8
src_addr
,
void
*
des_addr
,
uint16
load_size
);
bool
system_rtc_mem_write
(
uint8
des_addr
,
const
void
*
src_addr
,
uint16
save_size
);
bool
system_rtc_mem_write
(
uint8
des_addr
,
const
void
*
src_addr
,
uint16
save_size
);
void
system_uart_swap
(
void
);
void
system_uart_swap
(
void
);
uint16
system_adc_read
(
void
);
uint16
system_adc_read
(
void
);
const
char
*
system_get_sdk_version
(
void
);
const
char
*
system_get_sdk_version
(
void
);
#define NULL_MODE 0x00
#define NULL_MODE 0x00
#define STATION_MODE 0x01
#define STATION_MODE 0x01
#define SOFTAP_MODE 0x02
#define SOFTAP_MODE 0x02
#define STATIONAP_MODE 0x03
#define STATIONAP_MODE 0x03
typedef
enum
_auth_mode
{
typedef
enum
_auth_mode
{
AUTH_OPEN
=
0
,
AUTH_OPEN
=
0
,
AUTH_WEP
,
AUTH_WEP
,
AUTH_WPA_PSK
,
AUTH_WPA_PSK
,
AUTH_WPA2_PSK
,
AUTH_WPA2_PSK
,
AUTH_WPA_WPA2_PSK
,
AUTH_WPA_WPA2_PSK
,
AUTH_MAX
AUTH_MAX
}
AUTH_MODE
;
}
AUTH_MODE
;
uint8
wifi_get_opmode
(
void
);
uint8
wifi_get_opmode
(
void
);
bool
wifi_set_opmode
(
uint8
opmode
);
bool
wifi_set_opmode
(
uint8
opmode
);
struct
bss_info
{
struct
bss_info
{
STAILQ_ENTRY
(
bss_info
)
next
;
STAILQ_ENTRY
(
bss_info
)
next
;
uint8
bssid
[
6
];
uint8
bssid
[
6
];
uint8
ssid
[
32
];
uint8
ssid
[
32
];
uint8
channel
;
uint8
channel
;
sint8
rssi
;
sint8
rssi
;
AUTH_MODE
authmode
;
AUTH_MODE
authmode
;
uint8
is_hidden
;
uint8
is_hidden
;
};
};
typedef
struct
_scaninfo
{
typedef
struct
_scaninfo
{
STAILQ_HEAD
(,
bss_info
)
*
pbss
;
STAILQ_HEAD
(,
bss_info
)
*
pbss
;
struct
espconn
*
pespconn
;
struct
espconn
*
pespconn
;
uint8
totalpage
;
uint8
totalpage
;
uint8
pagenum
;
uint8
pagenum
;
uint8
page_sn
;
uint8
page_sn
;
uint8
data_cnt
;
uint8
data_cnt
;
}
scaninfo
;
}
scaninfo
;
typedef
void
(
*
scan_done_cb_t
)(
void
*
arg
,
STATUS
status
);
typedef
void
(
*
scan_done_cb_t
)(
void
*
arg
,
STATUS
status
);
struct
station_config
{
struct
station_config
{
uint8
ssid
[
32
];
uint8
ssid
[
32
];
uint8
password
[
64
];
uint8
password
[
64
];
uint8
bssid_set
;
// Note: If bssid_set is 1, station will just connect to the router
uint8
bssid_set
;
// Note: If bssid_set is 1, station will just connect to the router
// with both ssid[] and bssid[] matched. Please check about this.
// with both ssid[] and bssid[] matched. Please check about this.
uint8
bssid
[
6
];
uint8
bssid
[
6
];
};
};
bool
wifi_station_get_config
(
struct
station_config
*
config
);
bool
wifi_station_get_config
(
struct
station_config
*
config
);
bool
wifi_station_set_config
(
struct
station_config
*
config
);
bool
wifi_station_set_config
(
struct
station_config
*
config
);
bool
wifi_station_connect
(
void
);
bool
wifi_station_connect
(
void
);
bool
wifi_station_disconnect
(
void
);
bool
wifi_station_disconnect
(
void
);
struct
scan_config
{
struct
scan_config
{
uint8
*
ssid
;
// Note: ssid == NULL, don't filter ssid.
uint8
*
ssid
;
// Note: ssid == NULL, don't filter ssid.
uint8
*
bssid
;
// Note: bssid == NULL, don't filter bssid.
uint8
*
bssid
;
// Note: bssid == NULL, don't filter bssid.
uint8
channel
;
// Note: channel == 0, scan all channels, otherwise scan set channel.
uint8
channel
;
// Note: channel == 0, scan all channels, otherwise scan set channel.
uint8
show_hidden
;
// Note: show_hidden == 1, can get hidden ssid routers' info.
uint8
show_hidden
;
// Note: show_hidden == 1, can get hidden ssid routers' info.
};
};
bool
wifi_station_scan
(
struct
scan_config
*
config
,
scan_done_cb_t
cb
);
bool
wifi_station_scan
(
struct
scan_config
*
config
,
scan_done_cb_t
cb
);
uint8
wifi_station_get_auto_connect
(
void
);
uint8
wifi_station_get_auto_connect
(
void
);
bool
wifi_station_set_auto_connect
(
uint8
set
);
bool
wifi_station_set_auto_connect
(
uint8
set
);
enum
{
enum
{
STATION_IDLE
=
0
,
STATION_IDLE
=
0
,
STATION_CONNECTING
,
STATION_CONNECTING
,
STATION_WRONG_PASSWORD
,
STATION_WRONG_PASSWORD
,
STATION_NO_AP_FOUND
,
STATION_NO_AP_FOUND
,
STATION_CONNECT_FAIL
,
STATION_CONNECT_FAIL
,
STATION_GOT_IP
STATION_GOT_IP
};
};
enum
dhcp_status
{
enum
dhcp_status
{
DHCP_STOPPED
,
DHCP_STOPPED
,
DHCP_STARTED
DHCP_STARTED
};
};
uint8
wifi_station_get_connect_status
(
void
);
uint8
wifi_station_get_connect_status
(
void
);
uint8
wifi_station_get_current_ap_id
(
void
);
uint8
wifi_station_get_current_ap_id
(
void
);
bool
wifi_station_ap_change
(
uint8
current_ap_id
);
bool
wifi_station_ap_change
(
uint8
current_ap_id
);
bool
wifi_station_ap_number_set
(
uint8
ap_number
);
bool
wifi_station_ap_number_set
(
uint8
ap_number
);
bool
wifi_station_dhcpc_start
(
void
);
bool
wifi_station_dhcpc_start
(
void
);
bool
wifi_station_dhcpc_stop
(
void
);
bool
wifi_station_dhcpc_stop
(
void
);
enum
dhcp_status
wifi_station_dhcpc_status
(
void
);
enum
dhcp_status
wifi_station_dhcpc_status
(
void
);
struct
softap_config
{
struct
softap_config
{
uint8
ssid
[
32
];
uint8
ssid
[
32
];
uint8
password
[
64
];
uint8
password
[
64
];
uint8
ssid_len
;
// Note: Recommend to set it according to your ssid
uint8
ssid_len
;
// Note: Recommend to set it according to your ssid
uint8
channel
;
// Note: support 1 ~ 13
uint8
channel
;
// Note: support 1 ~ 13
AUTH_MODE
authmode
;
// Note: Don't support AUTH_WEP in softAP mode.
AUTH_MODE
authmode
;
// Note: Don't support AUTH_WEP in softAP mode.
uint8
ssid_hidden
;
// Note: default 0
uint8
ssid_hidden
;
// Note: default 0
uint8
max_connection
;
// Note: default 4, max 4
uint8
max_connection
;
// Note: default 4, max 4
uint
8
beacon_interval
;
// Note: support 100 ~ 60000 ms, default 100
uint
16
beacon_interval
;
// Note: support 100 ~ 60000 ms, default 100
};
};
bool
wifi_softap_get_config
(
struct
softap_config
*
config
);
bool
wifi_softap_get_config
(
struct
softap_config
*
config
);
bool
wifi_softap_set_config
(
struct
softap_config
*
config
);
bool
wifi_softap_set_config
(
struct
softap_config
*
config
);
struct
station_info
{
struct
station_info
{
STAILQ_ENTRY
(
station_info
)
next
;
STAILQ_ENTRY
(
station_info
)
next
;
uint8
bssid
[
6
];
uint8
bssid
[
6
];
struct
ip_addr
ip
;
struct
ip_addr
ip
;
};
};
struct
dhcps_lease
{
struct
dhcps_lease
{
uint32
start_ip
;
uint32
start_ip
;
uint32
end_ip
;
uint32
end_ip
;
};
};
struct
station_info
*
wifi_softap_get_station_info
(
void
);
struct
station_info
*
wifi_softap_get_station_info
(
void
);
void
wifi_softap_free_station_info
(
void
);
void
wifi_softap_free_station_info
(
void
);
uint8
wifi_station_get_ap_info
(
struct
station_config
config
[]);
uint8
wifi_station_get_ap_info
(
struct
station_config
config
[]);
bool
wifi_softap_dhcps_start
(
void
);
bool
wifi_softap_dhcps_start
(
void
);
bool
wifi_softap_dhcps_stop
(
void
);
bool
wifi_softap_dhcps_stop
(
void
);
bool
wifi_softap_set_dhcps_lease
(
struct
dhcps_lease
*
please
);
bool
wifi_softap_set_dhcps_lease
(
struct
dhcps_lease
*
please
);
enum
dhcp_status
wifi_softap_dhcps_status
(
void
);
enum
dhcp_status
wifi_softap_dhcps_status
(
void
);
#define STATION_IF 0x00
#define STATION_IF 0x00
#define SOFTAP_IF 0x01
#define SOFTAP_IF 0x01
bool
wifi_get_ip_info
(
uint8
if_index
,
struct
ip_info
*
info
);
bool
wifi_get_ip_info
(
uint8
if_index
,
struct
ip_info
*
info
);
bool
wifi_set_ip_info
(
uint8
if_index
,
struct
ip_info
*
info
);
bool
wifi_set_ip_info
(
uint8
if_index
,
struct
ip_info
*
info
);
bool
wifi_get_macaddr
(
uint8
if_index
,
uint8
*
macaddr
);
bool
wifi_get_macaddr
(
uint8
if_index
,
uint8
*
macaddr
);
bool
wifi_set_macaddr
(
uint8
if_index
,
uint8
*
macaddr
);
bool
wifi_set_macaddr
(
uint8
if_index
,
uint8
*
macaddr
);
uint8
wifi_get_channel
(
void
);
uint8
wifi_get_channel
(
void
);
bool
wifi_set_channel
(
uint8
channel
);
bool
wifi_set_channel
(
uint8
channel
);
void
wifi_status_led_install
(
uint8
gpio_id
,
uint32
gpio_name
,
uint8
gpio_func
);
void
wifi_status_led_install
(
uint8
gpio_id
,
uint32
gpio_name
,
uint8
gpio_func
);
void
wifi_status_led_uninstall
();
void
wifi_status_led_uninstall
();
/** Get the absolute difference between 2 u32_t values (correcting overflows)
/** Get the absolute difference between 2 u32_t values (correcting overflows)
* 'a' is expected to be 'higher' (without overflow) than 'b'. */
* 'a' is expected to be 'higher' (without overflow) than 'b'. */
#define ESP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1)))
#define ESP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1)))
void
wifi_promiscuous_enable
(
uint8
promiscuous
);
void
wifi_promiscuous_enable
(
uint8
promiscuous
);
typedef
void
(
*
wifi_promiscuous_cb_t
)(
uint8
*
buf
,
uint16
len
);
typedef
void
(
*
wifi_promiscuous_cb_t
)(
uint8
*
buf
,
uint16
len
);
void
wifi_set_promiscuous_rx_cb
(
wifi_promiscuous_cb_t
cb
);
void
wifi_set_promiscuous_rx_cb
(
wifi_promiscuous_cb_t
cb
);
enum
phy_mode
{
enum
phy_mode
{
PHY_MODE_11B
=
1
,
PHY_MODE_11B
=
1
,
PHY_MODE_11G
=
2
,
PHY_MODE_11G
=
2
,
PHY_MODE_11N
=
3
PHY_MODE_11N
=
3
};
};
enum
phy_mode
wifi_get_phy_mode
(
void
);
enum
phy_mode
wifi_get_phy_mode
(
void
);
bool
wifi_set_phy_mode
(
enum
phy_mode
mode
);
bool
wifi_set_phy_mode
(
enum
phy_mode
mode
);
enum
sleep_type
{
enum
sleep_type
{
NONE_SLEEP_T
=
0
,
NONE_SLEEP_T
=
0
,
LIGHT_SLEEP_T
,
LIGHT_SLEEP_T
,
MODEM_SLEEP_T
MODEM_SLEEP_T
};
};
bool
wifi_set_sleep_type
(
enum
sleep_type
type
);
bool
wifi_set_sleep_type
(
enum
sleep_type
type
);
enum
sleep_type
wifi_get_sleep_type
(
void
);
enum
sleep_type
wifi_get_sleep_type
(
void
);
#endif
#endif
lib/libmain.a
View file @
cf4cd8f4
No preview for this file type
lua_examples/yet-another-dht22.lua
0 → 100644
View file @
cf4cd8f4
------------------------------------------------------------------------------
-- DHT11/22 query module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- print("DHT11", require("dht22").read(4))
-- print("DHT22", require("dht22").read(4, true))
-- NB: the very first read sometimes fails
------------------------------------------------------------------------------
local
M
do
-- cache
local
gpio
=
gpio
local
val
=
gpio
.
read
local
waitus
=
tmr
.
delay
--
local
read
=
function
(
pin
,
dht22
)
-- wait for pin value
local
w
=
function
(
v
)
local
c
=
255
while
c
>
0
and
val
(
pin
)
~=
v
do
c
=
c
-
1
end
return
c
end
-- NB: we preallocate incoming data buffer
-- or precise timing in reader gets broken
local
b
=
{
0
,
0
,
0
,
0
,
0
}
-- kick the device
gpio
.
mode
(
pin
,
gpio
.
INPUT
,
gpio
.
PULLUP
)
gpio
.
write
(
pin
,
1
)
waitus
(
10
)
gpio
.
mode
(
pin
,
gpio
.
OUTPUT
)
gpio
.
write
(
pin
,
0
)
waitus
(
20000
)
gpio
.
write
(
pin
,
1
)
gpio
.
mode
(
pin
,
gpio
.
INPUT
,
gpio
.
PULLUP
)
-- wait for device presense
if
w
(
0
)
==
0
or
w
(
1
)
==
0
or
w
(
0
)
==
0
then
return
nil
,
0
end
-- receive 5 octets of data, msb first
for
i
=
1
,
5
do
local
x
=
0
for
j
=
1
,
8
do
x
=
x
+
x
if
w
(
1
)
==
0
then
return
nil
,
1
end
-- 70us for 1, 27 us for 0
waitus
(
30
)
if
val
(
pin
)
==
1
then
x
=
x
+
1
if
w
(
0
)
==
0
then
return
nil
,
2
end
end
end
b
[
i
]
=
x
end
-- check crc. NB: calculating in receiver loop breaks timings
local
crc
=
0
for
i
=
1
,
4
do
crc
=
(
crc
+
b
[
i
])
%
256
end
if
crc
~=
b
[
5
]
then
return
nil
,
3
end
-- convert
local
t
,
h
-- DHT22: values in tenths of unit, temperature can be negative
if
dht22
then
h
=
b
[
1
]
*
256
+
b
[
2
]
t
=
b
[
3
]
*
256
+
b
[
4
]
if
t
>
0x8000
then
t
=
-
(
t
-
0x8000
)
end
-- DHT11: no negative temperatures, only integers
-- NB: return in 0.1 Celsius
else
h
=
10
*
b
[
1
]
t
=
10
*
b
[
3
]
end
return
t
,
h
end
-- expose interface
M
=
{
read
=
read
,
}
end
return
M
lua_examples/yet-another-ds18b20.lua
0 → 100644
View file @
cf4cd8f4
------------------------------------------------------------------------------
-- DS18B20 query module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- for k, v in pairs(require("ds18b20").read(4)) do print(k, v) end
------------------------------------------------------------------------------
local
M
do
local
format_addr
=
function
(
a
)
return
(
"%02x-%02x%02x%02x%02x%02x%02x"
):
format
(
a
:
byte
(
1
),
a
:
byte
(
7
),
a
:
byte
(
6
),
a
:
byte
(
5
),
a
:
byte
(
4
),
a
:
byte
(
3
),
a
:
byte
(
2
)
)
end
local
read
=
function
(
pin
,
delay
)
local
ow
=
require
(
"ow"
)
-- get list of relevant devices
local
d
=
{
}
ow
.
setup
(
pin
)
ow
.
reset_search
(
pin
)
while
true
do
tmr
.
wdclr
()
local
a
=
ow
.
search
(
pin
)
if
not
a
then
break
end
if
ow
.
crc8
(
a
)
==
0
and
(
a
:
byte
(
1
)
==
0x10
or
a
:
byte
(
1
)
==
0x28
)
then
d
[
#
d
+
1
]
=
a
end
end
-- conversion command for all
ow
.
reset
(
pin
)
ow
.
skip
(
pin
)
ow
.
write
(
pin
,
0x44
,
1
)
-- wait a bit
tmr
.
delay
(
delay
or
100000
)
-- iterate over devices
local
r
=
{
}
for
i
=
1
,
#
d
do
tmr
.
wdclr
()
-- read rom command
ow
.
reset
(
pin
)
ow
.
select
(
pin
,
d
[
i
])
ow
.
write
(
pin
,
0xBE
,
1
)
-- read data
local
x
=
ow
.
read_bytes
(
pin
,
9
)
if
ow
.
crc8
(
x
)
==
0
then
local
t
=
(
x
:
byte
(
1
)
+
x
:
byte
(
2
)
*
256
)
*
625
-- NB: temperature in Celcius * 10^4
r
[
format_addr
(
d
[
i
])]
=
t
d
[
i
]
=
nil
end
end
return
r
end
-- expose
M
=
{
read
=
read
,
}
end
return
M
lua_modules/http/http-example.lua
View file @
cf4cd8f4
...
@@ -6,9 +6,8 @@
...
@@ -6,9 +6,8 @@
------------------------------------------------------------------------------
------------------------------------------------------------------------------
require
(
"http"
).
createServer
(
80
,
function
(
req
,
res
)
require
(
"http"
).
createServer
(
80
,
function
(
req
,
res
)
-- analyse method and url
-- analyse method and url
print
(
"+R"
,
req
.
method
,
req
.
url
)
print
(
"+R"
,
req
.
method
,
req
.
url
,
node
.
heap
()
)
-- setup handler of headers, if any
-- setup handler of headers, if any
--[[
req
.
onheader
=
function
(
self
,
name
,
value
)
req
.
onheader
=
function
(
self
,
name
,
value
)
-- print("+H", name, value)
-- print("+H", name, value)
-- E.g. look for "content-type" header,
-- E.g. look for "content-type" header,
...
@@ -34,8 +33,7 @@ require("http").createServer(80, function(req, res)
...
@@ -34,8 +33,7 @@ require("http").createServer(80, function(req, res)
res
:
finish
()
res
:
finish
()
end
end
end
end
]]
-- or just do something not waiting till body (if any) comes
-- or just do something not waiting till body (if any) comes
--res:finish("Hello, world!")
--res:finish("Hello, world!")
res
:
finish
(
"Salut, monde!"
)
--
res:finish("Salut, monde!")
end
)
end
)
lua_modules/http/http.lua
View file @
cf4cd8f4
...
@@ -87,9 +87,7 @@ do
...
@@ -87,9 +87,7 @@ do
return
res
return
res
end
end
tmr
.
wdclr
()
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- HTTP parser
-- HTTP parser
------------------------------------------------------------------------------
------------------------------------------------------------------------------
local
http_handler
=
function
(
handler
)
local
http_handler
=
function
(
handler
)
...
@@ -190,8 +188,6 @@ do
...
@@ -190,8 +188,6 @@ do
end
end
end
end
tmr
.
wdclr
()
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- HTTP server
-- HTTP server
------------------------------------------------------------------------------
------------------------------------------------------------------------------
...
...
pre_build/0.9.5/nodemcu_20150126.bin
0 → 100644
View file @
cf4cd8f4
File added
pre_build/latest/nodemcu_latest.bin
View file @
cf4cd8f4
No preview for this file type
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