docs: Add wipy and network.server documentation.

pull/1521/head
danicampora 2015-10-19 15:19:34 +02:00
rodzic 2e0cd20a1d
commit 36ae417c9f
8 zmienionych plików z 95 dodań i 27 usunięć

Wyświetl plik

@ -91,10 +91,12 @@ STATIC const mp_arg_t network_server_args[] = {
{ MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
}; };
STATIC mp_obj_t network_server_new (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t network_server_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
// parse args // parse args
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args)]; mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(args), network_server_args, args); mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), network_server_args, args);
// check the server id // check the server id
if (args[0].u_obj != MP_OBJ_NULL) { if (args[0].u_obj != MP_OBJ_NULL) {
@ -108,9 +110,8 @@ STATIC mp_obj_t network_server_new (mp_uint_t n_args, const mp_obj_t *pos_args,
self->base.type = &network_server_type; self->base.type = &network_server_type;
network_server_init_helper(self, &args[1]); network_server_init_helper(self, &args[1]);
return self; return (mp_obj_t)self;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_new_obj, 0, network_server_new);
STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t network_server_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args // parse args
@ -152,7 +153,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan }, { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&mod_network_nic_type_wlan },
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
{ MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_new_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_server), (mp_obj_t)&network_server_type },
#endif #endif
}; };
@ -169,7 +170,7 @@ STATIC const mp_map_elem_t network_server_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&network_server_init_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&network_server_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&network_server_deinit_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&network_server_deinit_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&network_server_timeout_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&network_server_timeout_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_running), (mp_obj_t)&network_server_running_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_isrunning), (mp_obj_t)&network_server_running_obj },
}; };
STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table);
@ -177,6 +178,7 @@ STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_di
STATIC const mp_obj_type_t network_server_type = { STATIC const mp_obj_type_t network_server_type = {
{ &mp_type_type }, { &mp_type_type },
.name = MP_QSTR_server, .name = MP_QSTR_server,
.make_new = network_server_make_new,
.locals_dict = (mp_obj_t)&network_server_locals_dict, .locals_dict = (mp_obj_t)&network_server_locals_dict,
}; };
#endif #endif

Wyświetl plik

@ -283,7 +283,7 @@ Q(init)
Q(deinit) Q(deinit)
Q(login) Q(login)
Q(timeout) Q(timeout)
Q(running) Q(isrunning)
// for WLAN class // for WLAN class
Q(WLAN) Q(WLAN)

Wyświetl plik

@ -105,6 +105,7 @@ it will fallback to loading the built-in ``ujson`` module.
machine.rst machine.rst
network.rst network.rst
wipy.rst
.. only:: port_esp8266 .. only:: port_esp8266

Wyświetl plik

@ -27,6 +27,40 @@ For example::
data = s.recv(1000) data = s.recv(1000)
s.close() s.close()
.. only:: port_wipy
.. _network.server:
class server
============
Constructors
------------
.. class:: server(id, ...)
Create a server instance, see ``init`` for parameters of initialization.
Methods
-------
.. method:: server.init(\*, login=('micro', 'python'), timeout=300)
Init (and effectively start the server). Optionally a new ``user``, ``password``
and ``timeout`` (in seconds) can be passed.
.. method:: server.deinit()
Stop the server
.. method:: server.timeout([timeout_in_seconds])
Get or set the server timeout.
.. method:: server.isrunning()
Returns ``True`` is the server is running, ``False`` otherwise.
.. only:: port_pyboard .. only:: port_pyboard
class CC3K class CC3K
@ -178,13 +212,13 @@ For example::
Dump the WIZnet5x00 registers. Useful for debugging. Dump the WIZnet5x00 registers. Useful for debugging.
class WLAN
==========
.. _network.WLAN: .. _network.WLAN:
.. only:: port_esp8266 .. only:: port_esp8266
class WLAN
==========
This class provides a driver for WiFi network processor in the ESP8266. Example usage:: This class provides a driver for WiFi network processor in the ESP8266. Example usage::
import network import network
@ -258,6 +292,9 @@ class WLAN
.. only:: port_wipy .. only:: port_wipy
class WLAN
==========
This class provides a driver for WiFi network processor in the WiPy. Example usage:: This class provides a driver for WiFi network processor in the WiPy. Example usage::
import network import network
@ -282,7 +319,7 @@ class WLAN
Methods Methods
------- -------
.. method:: init(mode, \*, ssid, security, key, channel, antenna) .. method:: wlan.init(mode, \*, ssid, security, key, channel, antenna)
Set or get the WiFi network processor configuration. Set or get the WiFi network processor configuration.

Wyświetl plik

@ -0,0 +1,15 @@
:mod:`wipy` -- WiPy specific features
=====================================
.. module:: wipy
:synopsis: WiPy specific features
The ``wipy`` module contains functions to control specific features of the
WiPy, such as the heartbeat LED.
Functions
---------
.. function:: heartbeat([enable])
Get or set the state (enabled or disabled) of the heartbeat LED.

Wyświetl plik

@ -119,9 +119,10 @@ The heart beat LED
------------------ ------------------
By default the heart beat LED flashes once every 4s to signal that the system is By default the heart beat LED flashes once every 4s to signal that the system is
alive. This can be overridden through the HeartBeat class: alive. This can be overridden through the :mod:`wipy` module::
``machine.HeartBeat().disable()`` import wipy
wipy.heartbeat(False)
There are currently 2 kinds of errors that you might see: There are currently 2 kinds of errors that you might see:

Wyświetl plik

@ -10,7 +10,7 @@ Quick reference for the WiPy
General board control (including sleep modes) General board control (including sleep modes)
--------------------------------------------- ---------------------------------------------
See :mod:`machine`. :: See the :mod:`machine` module::
import machine import machine
@ -198,14 +198,26 @@ See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
machine.sleep() machine.sleep()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up # now, connect to the FTP or the Telnet server and the WiPy will wake-up
Heart beat LED Telnet and FTP server
-------------- ---------------------
See :ref:`machine.HeartBeat <machine.HeartBeat>`. :: See :ref:`network.server <network.server>` ::
from machine import HeartBeat from network import network
# disable the heart beat indication (you are free to use this LED connected to GP25) # init with new user, pass word and seconds timeout
HeartBeat().disable() server = server.init(login=('user', 'password'), timeout=60)
# enable the heart beat again server.timeout(300) # change the timeout
HeartBeat().enable() server.timeout() # get the timeout
server.isrunning() # check wether the server is running or not
HeartBeat LED
-------------
See :mod:`wipy`. ::
import wipy
wipy.heartbeat(False) # disable the heartbeat LED
wipy.heartbeat(True) # enable the heartbeat LED
wipy.heartbeat() # get the heartbeat state

Wyświetl plik

@ -12,18 +12,18 @@ if not 'LaunchPad' in mch and not'WiPy' in mch:
server = network.server() server = network.server()
print(server.timeout() == 300) print(server.timeout() == 300)
print(server.running() == True) print(server.isrunning() == True)
server.deinit() server.deinit()
print(server.running() == False) print(server.isrunning() == False)
server.init(login=('test-user', 'test-password'), timeout=60) server.init(login=('test-user', 'test-password'), timeout=60)
print(server.running() == True) print(server.isrunning() == True)
print(server.timeout() == 60) print(server.timeout() == 60)
server.deinit() server.deinit()
print(server.running() == False) print(server.isrunning() == False)
server.init() server.init()
print(server.running() == True) print(server.isrunning() == True)
try: try:
server.init(1) server.init(1)