2014-11-07 05:59:19 +01:00
|
|
|
|
# **nodeMcu API Instruction** #
|
2014-11-10 12:52:02 +01:00
|
|
|
|
###version 0.2 2014-11-10
|
2014-11-07 08:40:43 +01:00
|
|
|
|
###change log:
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
2014-11-11 05:31:45 +01:00
|
|
|
|
2014-11-11<br />
|
|
|
|
|
add file.seek() api to file module<br />
|
|
|
|
|
now max 6 pwm channel is supported<br />
|
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
2014-11-10<br />
|
|
|
|
|
change log module to file module<br />
|
|
|
|
|
now file operation support multiple read/write<br />
|
|
|
|
|
for now file module only allowed one file opened<br />
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
2014-11-5<br />
|
|
|
|
|
delete log operation api from node module<br />
|
|
|
|
|
add log module<br />
|
|
|
|
|
modify wifi module api<br />
|
|
|
|
|
modify node.key long_press and short_press default function<br />
|
|
|
|
|
key is triged only when key is released<br />
|
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
# Summary
|
|
|
|
|
- Easy to access wireless router
|
2014-11-10 14:00:17 +01:00
|
|
|
|
- Based on Lua 5.1.4, Developers are supposed to have experience with Lua Program language.
|
|
|
|
|
- Event-Drive programming modal.
|
|
|
|
|
- Build-in file, timer, pwm, i2c, net, gpio, wifi module.
|
|
|
|
|
- Serial Port BaudRate:9600
|
|
|
|
|
- Re-mapped GPIO pin, use the index to program gpio, i2c, pwm.
|
|
|
|
|
- GPIO Map Table:
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope="col">IO index</th><th scope="col">ESP8266 pin</th><th scope="col">IO index</th><th scope="col">ESP8266 pin</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>0</td><td>GPIO12</td><td>8</td><td>GPIO0</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>1</td><td>GPIO13</td><td>9</td><td>GPIO2</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>2</td><td>GPIO14</td><td>10</td><td>GPIO4</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>3</td><td>GPIO15</td><td>11</td><td>GPIO5</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>4</td><td>GPIO3</td><td></td><td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>5</td><td>GPIO1</td><td></td><td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>6</td><td>GPIO9</td><td></td><td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>7</td><td>GPIO10</td<td></td><td></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Firmware Program
|
2014-11-07 08:06:43 +01:00
|
|
|
|
###Address
|
|
|
|
|
|
|
|
|
|
eagle.app.v6.flash.bin: 0x00000<br />
|
|
|
|
|
eagle.app.v6.irom0text.bin: 0x10000<br />
|
|
|
|
|
esp_init_data_default.bin: 0x7c000<br />
|
|
|
|
|
blank.bin: 0x7e000
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#node module
|
|
|
|
|
<a id="nm_restart"></a>
|
|
|
|
|
## node.restart()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
restart the chip.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
node.restart()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
node.restart();
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nm_dsleep"></a>
|
|
|
|
|
## node.dsleep()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
Enter deep sleep mode, wake up when timed out<br />
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
node.dsleep(us)<br />
|
2014-11-10 14:00:17 +01:00
|
|
|
|
**-Note:** This function can only be used in the condition that esp8266 PIN32(RST) and PIN8(XPD_DCDC) are connected together.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
us: sleep time in micro second
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
node.dsleep(us);
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nm_chipid"></a>
|
|
|
|
|
## node.chipid()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
return chip ID
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
node.chipid()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-10 14:00:17 +01:00
|
|
|
|
number:chip ID
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-07 08:40:43 +01:00
|
|
|
|
id = node.chipid();
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nm_heap"></a>
|
|
|
|
|
## node.heap()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
return the remain HEAP size in bytes
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
node.heap()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-10 14:00:17 +01:00
|
|
|
|
number: system heap size left in bytes
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-07 08:40:43 +01:00
|
|
|
|
heap_size = node.heap();
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nm_key"></a>
|
|
|
|
|
## node.key()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
define button function.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
node.key(type, function())
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
type: type is either string "long" or "short". long: press the key for 3 seconds, short: press shortly(less than 3 seconds)<br />
|
|
|
|
|
function(): user defined function which is called when key is pressed. If nil, cancling the user defined function.<br />
|
2014-11-07 08:40:43 +01:00
|
|
|
|
Default function: long: change LED blinking rate, short: reset chip
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
2014-11-07 08:40:43 +01:00
|
|
|
|
node.key("long", function(){print('hello world')})
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nm_led"></a>
|
|
|
|
|
## node.led()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
setup the on/off time for led
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-07 08:40:43 +01:00
|
|
|
|
node.led(low, high)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
Low: LED off time, LED keeps on when low=0. Unit: milliseconds, time resolution: 80~100ms<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
High: LED off time. Unit: milliseconds, time resolution: 80~100ms
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- turn led on forever.
|
2014-11-07 08:40:43 +01:00
|
|
|
|
node.led(0);
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
#file module
|
|
|
|
|
<a id="fl_remove"></a>
|
|
|
|
|
## file.remove()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
remove file from file system.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.remove(filename)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
filename: file to remove
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- remove "foo.lua" from file system.
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.remove("foo.lua")
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.close()](#fl_close)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_open"></a>
|
|
|
|
|
## file.open()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 10:16:07 +01:00
|
|
|
|
open file.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open(filename, mode)
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Parameters
|
2014-11-10 10:16:07 +01:00
|
|
|
|
filename: file to be opened, directories are not supported<br />
|
|
|
|
|
mode:<br />
|
|
|
|
|
"r": read mode (the default)<br />
|
|
|
|
|
"w": write mode<br />
|
|
|
|
|
"a": append mode<br />
|
|
|
|
|
"r+": update mode, all previous data is preserved<br />
|
|
|
|
|
"w+": update mode, all previous data is erased<br />
|
|
|
|
|
"a+": append update mode, previous data is preserved, writing is only allowed at the end of file
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- open 'init.lua', print the first line.
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open("init.lua", "r")
|
|
|
|
|
print(file.readline())
|
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.close()](#fl_close)<br />
|
|
|
|
|
**-** [file.readline()](#fl_readline)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_close"></a>
|
|
|
|
|
## file.close()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 10:16:07 +01:00
|
|
|
|
close the file.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- open 'init.lua', print the first line.
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open("init.lua", "r")
|
|
|
|
|
print(file.readline())
|
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.readline()](#fl_readline)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_readline"></a>
|
|
|
|
|
## file.readline()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
read one line of file which is opened before.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.readline()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 10:16:07 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file content in string, line by line
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print the first line of 'init.lua'
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open("init.lua", "r")
|
|
|
|
|
print(file.readline())
|
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.close()](#fl_close)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_writeline"></a>
|
|
|
|
|
## file.writeline()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 12:52:02 +01:00
|
|
|
|
write string to file and add a '\n' at the end.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.writeline(string)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 10:16:07 +01:00
|
|
|
|
string: content to be write to file
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-10 12:52:02 +01:00
|
|
|
|
true: write ok.
|
|
|
|
|
nil: there is error
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- open 'init.lua' in 'a+' mode
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open("init.lua", "a+")
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- write 'foo bar' to the end of the file
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.writeline('foo bar')
|
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.write()](#fl_write)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_write"></a>
|
|
|
|
|
## file.write()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 10:16:07 +01:00
|
|
|
|
write string to file.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.write(string)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 10:16:07 +01:00
|
|
|
|
string: content to be write to file.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 12:52:02 +01:00
|
|
|
|
####Returns
|
|
|
|
|
true: write ok.
|
|
|
|
|
nil: there is error
|
|
|
|
|
|
|
|
|
|
####Example
|
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- open 'init.lua' in 'a+' mode
|
2014-11-10 12:52:02 +01:00
|
|
|
|
file.open("init.lua", "a+")
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- write 'foo bar' to the end of the file
|
2014-11-10 12:52:02 +01:00
|
|
|
|
file.write('foo bar')
|
|
|
|
|
file.close()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
####See also
|
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.writeline()](#fl_writeline)
|
|
|
|
|
|
|
|
|
|
<a id="fl_flush"></a>
|
|
|
|
|
## file.flush()
|
|
|
|
|
####Description
|
|
|
|
|
flush to file.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
file.flush()
|
|
|
|
|
|
|
|
|
|
####Parameters
|
|
|
|
|
nil
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-10 10:16:07 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- open 'init.lua' in 'a+' mode
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.open("init.lua", "a+")
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- write 'foo bar' to the end of the file
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.write('foo bar')
|
2014-11-10 12:52:02 +01:00
|
|
|
|
file.flush()
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.writeline()](#fl_writeline)
|
2014-10-21 06:27:17 +02:00
|
|
|
|
|
2014-11-11 05:31:45 +01:00
|
|
|
|
<a id="fl_seek"></a>
|
|
|
|
|
## file.seek()
|
|
|
|
|
####Description
|
|
|
|
|
Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
file.seek(whence, offset)
|
|
|
|
|
|
|
|
|
|
####Parameters
|
|
|
|
|
whence:<br />
|
|
|
|
|
"set": base is position 0 (beginning of the file);<br />
|
|
|
|
|
"cur": base is current position;(default value)<br />
|
|
|
|
|
"end": base is end of file;<br />
|
|
|
|
|
offset: default 0
|
|
|
|
|
|
|
|
|
|
####Returns
|
|
|
|
|
success: returns the final file position<br />
|
|
|
|
|
fail: returns nil
|
|
|
|
|
|
|
|
|
|
####Example
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
-- open 'init.lua' in 'a+' mode
|
|
|
|
|
file.open("init.lua", "a+")
|
|
|
|
|
-- write 'foo bar' to the end of the file
|
|
|
|
|
file.write('foo bar')
|
|
|
|
|
file.flush()
|
|
|
|
|
file.seek("set")
|
|
|
|
|
print(file.readline())
|
|
|
|
|
file.close()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
####See also
|
|
|
|
|
**-** [file.open()](#fl_open)<br />
|
|
|
|
|
**-** [file.writeline()](#fl_writeline)
|
|
|
|
|
|
2014-11-10 10:16:07 +01:00
|
|
|
|
<a id="fl_list"></a>
|
|
|
|
|
## file.list()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
list all files.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
2014-11-10 10:16:07 +01:00
|
|
|
|
file.list()
|
2014-10-13 15:17:02 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
a lua table which contains the {file name: file size} pairs
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
2014-11-10 10:16:07 +01:00
|
|
|
|
l = file.list();
|
2014-11-07 08:40:43 +01:00
|
|
|
|
for k,v in l do
|
|
|
|
|
print("name:"..k..", size:"..v)
|
|
|
|
|
end
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 10:16:07 +01:00
|
|
|
|
**-** [file.remove()](#fl_remove)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
#wifi module
|
|
|
|
|
##CONSTANT
|
2014-11-07 08:06:43 +01:00
|
|
|
|
wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="wf_setmode"></a>
|
|
|
|
|
## wifi.setmode(mode)
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
setup wifi operation mode.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.setmode(mode)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
mode: value should be: wifi.STATION, wifi.SOFTAP or wifi.STATIONAP
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
current mode after setup
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.setmode(wifi.STATION)
|
|
|
|
|
```
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.getmode()](#wf_getmode)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="wf_getmode"></a>
|
|
|
|
|
## wifi.getmode(mode)
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-07 08:40:43 +01:00
|
|
|
|
get wifi operation mode.
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.getmode()
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
wifi operation mode
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
print(wifi.getmode())
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.setmode()](#wf_setmode)
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="wf_startsmart"></a>
|
|
|
|
|
## wifi.startsmart()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
starts to auto configuration, if success set up ssid and pwd automatically .
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.startsmart(channel, function succeed_callback())
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
channel: 1~13, startup channel for searching, if nil, default to 6. 20 seconds for each channel.<br />
|
|
|
|
|
succeed_callback: callback function called after configuration, which is called when got password and connected to AP.
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.startsmart(6, cb())
|
|
|
|
|
```
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.stopsmart()](#wf_stopsmart)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="wf_stopsmart"></a>
|
|
|
|
|
## wifi.stopsmart()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
stop the configuring process.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.stopsmart()
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.stopsmart()
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.startsmart()](#wf_startsmart)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
#wifi.sta module
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_config"></a>
|
|
|
|
|
## wifi.sta.config()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set ssid and password in station mode.
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.config(ssid, password)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
ssid: string which is less than 32 bytes.<br />
|
|
|
|
|
password: string which is less than 64 bytes.
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.sta.config("myssid","mypassword")
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.sta.connect()](#ws_connect)<br />
|
|
|
|
|
**-** [wifi.sta.disconnect()](#ws_disconnect)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_connect"></a>
|
|
|
|
|
## wifi.sta.connect()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
connect to AP in station mode.
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.connect()
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.sta.connect()
|
|
|
|
|
```
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.sta.disconnect()](#ws_disconnect)<br />
|
|
|
|
|
**-** [wifi.sta.config()](#ws_config)
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_disconnect"></a>
|
|
|
|
|
## wifi.sta.disconnect()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
disconnect from AP in station mode.
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.disconnect()
|
2014-10-13 14:39:28 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.sta.disconnect()
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 12:52:02 +01:00
|
|
|
|
**-** [wifi.sta.config()](#ws_config)<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
**-** [wifi.sta.connect()](#ws_connect)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_autoconnect"></a>
|
|
|
|
|
## wifi.sta.autoconnect()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
auto connect to AP in station mode.
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.autoconnect(auto)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
auto: 0 to disable auto connecting. 1 to enable auto connecting
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
wifi.sta.autoconnect()
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 12:52:02 +01:00
|
|
|
|
**-** [wifi.sta.config()](#ws_config)<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
**-** [wifi.sta.connect()](#ws_connect)<br />
|
|
|
|
|
**-** [wifi.sta.disconnect()](#ws_disconnect)
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_getip"></a>
|
|
|
|
|
## wifi.sta.getip()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get ip address in station mode.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.getip()
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
ip address in string, for example:"192.168.0.111"
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print current ip
|
2014-11-07 05:59:19 +01:00
|
|
|
|
print(wifi.sta.getip())
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-07 08:40:43 +01:00
|
|
|
|
**-** [wifi.sta.getmac()](#ws_getmac)
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="ws_getmac"></a>
|
|
|
|
|
## wifi.sta.getmac()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get mac address in station mode.
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.sta.getmac()
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
mac address in string, for example:"18-33-44-FE-55-BB"
|
|
|
|
|
|
|
|
|
|
####Example
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print current mac address
|
2014-11-07 05:59:19 +01:00
|
|
|
|
print(wifi.sta.getmac())
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 12:52:02 +01:00
|
|
|
|
**-** [wifi.sta.getip()](#ws_getip)
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
#wifi.ap module
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
<a id="wa_config"></a>
|
|
|
|
|
## wifi.ap.config()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set ssid and password in ap mode.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.ap.config(cfg)
|
|
|
|
|
|
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
cfg: lua table to setup ap.
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example:
|
2014-10-13 14:50:24 +02:00
|
|
|
|
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
cfg={}
|
|
|
|
|
cfg.ssid="myssid"
|
|
|
|
|
cfg.pwd="mypwd"
|
|
|
|
|
wifi.ap.setconfig(cfg)
|
|
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
wifi.ap.config(ssid, 'password')
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-07 08:40:43 +01:00
|
|
|
|
**-** []()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="wa_getip"></a>
|
|
|
|
|
## wifi.ap.getip()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get ip in ap mode.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
wifi.ap.getip()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
ip address in string, for example:"192.168.0.111"
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
wifi.ap.getip()
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
2014-11-10 12:52:02 +01:00
|
|
|
|
**-** [wifi.ap.getmac()](#wa_getmac)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="wa_getmac"></a>
|
|
|
|
|
## wifi.ap.getmac()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get mac address in ap mode.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
wifi.ap.getmac()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
mac address in string, for example:"1A-33-44-FE-55-BB"
|
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
wifi.ap.getmac()
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [wifi.ap.getip()](#wa_getip)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#timer module
|
|
|
|
|
<a id="tm_delay"></a>
|
|
|
|
|
## tmr.delay()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
delay us micro seconds.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
tmr.dealy(us)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
us: delay time in micro second
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- delay 100us
|
2014-11-07 05:59:19 +01:00
|
|
|
|
tmr.delay(100)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [tmr.now()](#tm_now)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="tm_now"></a>
|
|
|
|
|
## tmr.now()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-10 14:00:17 +01:00
|
|
|
|
return the current value of system counter: uint32, us.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
tmr.now()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
uint32: value of counter
|
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print current value of counter
|
2014-11-07 05:59:19 +01:00
|
|
|
|
print(tmr.now())
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [tmr.delay()](#tm_delay)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="tm_alarm"></a>
|
|
|
|
|
## tmr.alarm()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
alarm time.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
tmr.alarm(interval, repeat, function do())
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
Interval: alarm time, unit: millisecond<br />
|
2014-11-07 08:40:43 +01:00
|
|
|
|
repeat: 0 - one time alarm, 1 - repeat<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
function do(): callback function for alarm timed out
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print "hello world" every 1000ms
|
2014-11-07 08:40:43 +01:00
|
|
|
|
tmr.alarm(1000, 1, function() print("hello world") end )
|
2014-11-07 05:59:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [tmr.now()](#tm_now)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="tm_stop"></a>
|
|
|
|
|
## tmr.stop()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
stop alarm.<br />
|
2014-11-10 14:00:17 +01:00
|
|
|
|
**-Note:** only one alarm is allowed, the previous one would be replaced if tmr.alarm() called again before tmr.stop().
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
tmr.stop()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil.
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- print "hello world" every 1000ms
|
2014-11-07 08:40:43 +01:00
|
|
|
|
tmr.alarm(1000, 1, function() print("hello world") end )
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- something else
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- stop alarm
|
2014-11-07 05:59:19 +01:00
|
|
|
|
tmr.stop()
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [tmr.now()](#tm_now)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#GPIO module
|
|
|
|
|
##CONSTANT
|
2014-11-07 08:06:43 +01:00
|
|
|
|
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="io_mode"></a>
|
|
|
|
|
## gpio.mode()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
initialize pin to GPIO mode, set the pin in/out mode.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
gpio.mode(pin, mode)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- set gpio 0 as output.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
gpio.mode(0, gpio.OUTPUT)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [gpio.read()](#io_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="io_read"></a>
|
|
|
|
|
## gpio.read()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
read pin value.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
gpio.read(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
number:0 - low, 1 - high
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- read value of gpio 0.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
gpio.read(0)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [gpio.mode()](#io_mode)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="io_write"></a>
|
|
|
|
|
## gpio.write()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set pin value.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
gpio.write(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
level: gpio.HIGH or gpio.LOW
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- set pin index 1 to GPIO mode, and set the pin to high.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
pin=1
|
|
|
|
|
gpio.mode(pin, gpio.OUTPUT)
|
|
|
|
|
gpio.write(pin, gpio.HIGH)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [gpio.mode()](#io_mode)<br />
|
|
|
|
|
**-** [gpio.read()](#io_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="io_trig"></a>
|
|
|
|
|
## gpio.trig()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set the interrupt callback function for pin.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
gpio.trig(pin, type, function(level))
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index<br />
|
2014-11-07 08:40:43 +01:00
|
|
|
|
type: "up", "down", "both", "low", "high", which represent rising edge, falling edge, both edge, low level, high level trig mode separately.<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
function(level): callback function when triggered. The gpio level is the param. Use previous callback function if undefined here.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- use pin 0 as the input pulse width counter
|
2014-11-07 05:59:19 +01:00
|
|
|
|
pulse0 = 0
|
|
|
|
|
du = 0
|
|
|
|
|
gpio.mode(0,gpio.INT)
|
|
|
|
|
function pin0cb(level)
|
|
|
|
|
du = tmr.now() – pulse0
|
|
|
|
|
print(du)
|
|
|
|
|
pulse0 = tmr.now()
|
|
|
|
|
if level == 1 then gpio.trig(0, "down ") else gpio.trig(0, "up ") end
|
|
|
|
|
end
|
|
|
|
|
gpio.trig(0, "down ",pin0cb)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [gpio.mode()](#io_mode)<br />
|
|
|
|
|
**-** [gpio.write()](#io_write)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#PWM module
|
|
|
|
|
<a id="pw_setup"></a>
|
|
|
|
|
## pwm.setup()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
pwm.setup(pin, clock, duty)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index<br />
|
|
|
|
|
clock: 1~500, pwm frequency<br />
|
|
|
|
|
duty: 0~100, pwm duty cycle in percentage
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
pwm.setup(0, 100, 50)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.start()](#pw_start)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_close"></a>
|
|
|
|
|
## pwm.close()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
quit PWM mode for specified pin.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
pwm.close(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pwm.close(0)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.start()](#pw_start)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_start"></a>
|
|
|
|
|
## pwm.start()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
pwm starts, you can detect the waveform on the gpio.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
pwm.start(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pwm.start(0)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.stop()](#pw_stop)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_stop"></a>
|
|
|
|
|
## pwm.stop()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
pause the output of PWM waveform.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
pwm.stop(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pwm.stop(0)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.start()](#pw_start)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_setclock"></a>
|
|
|
|
|
## pwm.setclock()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
set pwm frequency for pin.<br />
|
|
|
|
|
**-Note:** setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
pwm.setclock(pin, clock)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index.<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
clock: 1~500, pwm frequency.
|
|
|
|
|
|
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pwm.setclock(0, 100)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.getclock()](#pw_getclock)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_getclock"></a>
|
|
|
|
|
## pwm.getclock()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get pwm frequency of pin.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
pwm.getclock(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
number:pwm frequency of pin
|
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
print(pwm.getclock(0))
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.setclock()](#pw_setclock)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_setduty"></a>
|
|
|
|
|
## pwm.setduty()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
set duty clycle for pin.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
pwm.setduty(pin, duty)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index<br />
|
|
|
|
|
duty: 0~100, pwm duty cycle in percentage
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pwm.setduty(0, 50)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.getduty()](#pw_getduty)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="pw_getduty"></a>
|
|
|
|
|
## pwm.getduty()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get duty clycle for pin.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
pwm.getduty(pin)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pin: 0~11, IO index
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- D0 is connected to green led
|
|
|
|
|
-- D1 is connected to blue led
|
|
|
|
|
-- D2 is connected to red led
|
2014-11-07 05:59:19 +01:00
|
|
|
|
pwm.setup(0,500,50)
|
|
|
|
|
pwm.setup(1,500,50)
|
|
|
|
|
pwm.setup(2,500,50)
|
|
|
|
|
pwm.start(0)
|
|
|
|
|
pwm.start(1)
|
|
|
|
|
pwm.start(2)
|
|
|
|
|
function led(r,g,b)
|
|
|
|
|
pwm.setduty(0,g)
|
|
|
|
|
pwm.setduty(1,b)
|
|
|
|
|
pwm.setduty(2,r)
|
|
|
|
|
end
|
2014-11-10 14:00:17 +01:00
|
|
|
|
led(50,0,0) -- set led to red
|
|
|
|
|
led(0,0,50) -- set led to blue.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [pwm.setduty()](#pw_setduty)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#net module
|
|
|
|
|
##CONSTANT
|
2014-11-07 08:06:43 +01:00
|
|
|
|
net.TCP, net.UDP
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="nt_createServer"></a>
|
|
|
|
|
## net.createServer()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
create a server.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
net.createServer(type, secure)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
type: net.TCP or net.UDP<br />
|
|
|
|
|
secure: true or false, true for safe link, false for ordinary link
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
net.server sub module
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
net.createServer(net.TCP, true)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createConnection()](#nt_createConnection)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="nt_createConnection"></a>
|
|
|
|
|
## net.createConnection()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
create a client.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
net.createConnection(type, secure)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
type: net.TCP or net.UDP<br />
|
|
|
|
|
secure: true or false, true for safe link, false for ordinary link
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
net.server sub module
|
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
net.createConnection(net.UDP, false)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#net.server module
|
|
|
|
|
<a id="ns_listen"></a>
|
|
|
|
|
## listen()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
listen on port from [ip] address.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
net.server.listen(port,[ip],function(net.socket))
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
port: port number<br />
|
|
|
|
|
ip:ip address string, can be omitted<br />
|
|
|
|
|
function(net.socket): callback function, pass to Caller function as param if a connection is created successfully
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- create a server
|
2014-11-07 05:59:19 +01:00
|
|
|
|
sv=net.createServer(net.TCP, false)
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- server listen on 80, if data received, print data to console, and send "hello world" to remote.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
sv:listen(80,function(c)
|
|
|
|
|
c:on("receive", function(sck, pl) print(pl) end)
|
|
|
|
|
c:send("hello world")
|
|
|
|
|
end)
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="ns_close"></a>
|
|
|
|
|
## close()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
close server.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
net.server.close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- create a server
|
2014-11-07 05:59:19 +01:00
|
|
|
|
sv=net.createServer(net.TCP, false)
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- close server
|
2014-11-07 05:59:19 +01:00
|
|
|
|
sv:close()
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#net.socket module
|
|
|
|
|
<a id="nk_connect"></a>
|
|
|
|
|
## connect()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
connect to remote.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
connect(port, ip)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
port: port number<br />
|
|
|
|
|
ip: ip address in string
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.socket:on()](#nk_on)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="nk_send"></a>
|
|
|
|
|
## send()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
send data to remote via connection.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
send(string, function(sent))
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
string: data in string which will be sent to remote<br />
|
|
|
|
|
function(sent): callback function for sending string
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.socket:on()](#nk_on)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="nk_on"></a>
|
|
|
|
|
## on()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
register callback function for event.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
on(event, function cb())
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-10 14:00:17 +01:00
|
|
|
|
event: string, which can be: "connection", "reconnection", "disconnection", "receive", "sent"<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
function cb(net.socket, [string]): callback function. The first param is the socket.<br />
|
2014-11-10 14:00:17 +01:00
|
|
|
|
If event is"receive", the second param is received data in string.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sk=net.createConnection(net.TCP, false)
|
|
|
|
|
sk:on("receive", function(sck, c) print(c) end )
|
|
|
|
|
sk:connect(80,"192.168.0.66")
|
|
|
|
|
sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="nk_close"></a>
|
|
|
|
|
## close()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
close socket.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
close()
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="nk_dns"></a>
|
|
|
|
|
## dns()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
get domain ip
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
dns(domain, function(net.socket, ip))
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
domain: domain name.<br />
|
|
|
|
|
function (net.socket, ip): callback function. The first param is the socket, the second param is the ip address in string.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [net.createServer()](#nt_createServer)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#i2c module
|
|
|
|
|
##CONSTANT
|
2014-11-07 08:06:43 +01:00
|
|
|
|
i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="ic_setup"></a>
|
|
|
|
|
## i2c.setup()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
initialize i2c.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
i2c.setup(id, pinSDA, pinSCL, speed)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id = 0<br />
|
2014-11-10 14:00:17 +01:00
|
|
|
|
pinSDA: 0~11, IO index<br />
|
|
|
|
|
pinSCL: 0~11, IO index<br />
|
2014-11-07 08:06:43 +01:00
|
|
|
|
speed: i2c.SLOW
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.read()](#ic_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="ic_start"></a>
|
|
|
|
|
## i2c.start()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
start i2c transporting.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
i2c.start(id)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id = 0
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.read()](#ic_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="ic_stop"></a>
|
|
|
|
|
## i2c.stop()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
stop i2c transporting.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
i2c.stop(id)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id = 0
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.read()](#ic_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="ic_address"></a>
|
|
|
|
|
## i2c.address()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
setup i2c address and read/write mode.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
i2c.address(id, device_addr, direction)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id=0<br />
|
|
|
|
|
device_addr: device address.<br />
|
|
|
|
|
direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.read()](#ic_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
<a id="ic_write"></a>
|
|
|
|
|
## i2c.write()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
write data to i2c, data can be multi numbers, string or lua table.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Syntax
|
|
|
|
|
i2c.write(id, data1, data2,...)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id=0<br />
|
|
|
|
|
data: data can be numbers, string or lua table.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
2014-11-07 08:40:43 +01:00
|
|
|
|
nil
|
2014-11-07 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
i2c.write(0, "hello", "world")
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.read()](#ic_read)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
<a id="ic_read"></a>
|
2014-11-07 05:59:19 +01:00
|
|
|
|
## i2c.read()
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Description
|
|
|
|
|
read data for len bytes.
|
|
|
|
|
|
|
|
|
|
####Syntax
|
|
|
|
|
i2c.read(id, len)
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Parameters
|
|
|
|
|
id=0<br />
|
|
|
|
|
len: data length
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Returns
|
|
|
|
|
string:data received.
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####Example
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
id=0
|
|
|
|
|
sda=1
|
|
|
|
|
scl=0
|
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- initialize i2c, set pin1 as sda, set pin0 as scl
|
2014-11-07 05:59:19 +01:00
|
|
|
|
i2c.setup(id,sda,scl,i2c.SLOW)
|
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- user defined function: read from reg_addr content of dev_addr
|
2014-11-07 05:59:19 +01:00
|
|
|
|
function read_reg(dev_addr, reg_addr)
|
|
|
|
|
i2c.start(id)
|
|
|
|
|
i2c.address(id, dev_addr ,i2c.TRANSMITTER)
|
|
|
|
|
i2c.write(id,reg_addr)
|
|
|
|
|
i2c.stop(id)
|
|
|
|
|
i2c.start(id)
|
|
|
|
|
i2c.address(id, dev_addr,i2c.RECEIVER)
|
|
|
|
|
c=i2c.read(id,1)
|
|
|
|
|
i2c.stop(id)
|
|
|
|
|
return c
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-10 14:00:17 +01:00
|
|
|
|
-- get content of register 0xAA of device 0x77
|
2014-11-07 05:59:19 +01:00
|
|
|
|
reg = read_reg(0x77, 0xAA)
|
|
|
|
|
pirnt(string.byte(reg))
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2014-11-07 08:06:43 +01:00
|
|
|
|
####See also
|
|
|
|
|
**-** [i2c.write()](#ic_write)
|
2014-10-16 16:20:05 +02:00
|
|
|
|
|