Commit 36ae417c authored by danicampora's avatar danicampora
Browse files

docs: Add wipy and network.server documentation.

parent 2e0cd20a
......@@ -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_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
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_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
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;
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) {
// 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 },
#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
};
......@@ -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_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_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);
......@@ -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 = {
{ &mp_type_type },
.name = MP_QSTR_server,
.make_new = network_server_make_new,
.locals_dict = (mp_obj_t)&network_server_locals_dict,
};
#endif
......@@ -283,7 +283,7 @@ Q(init)
Q(deinit)
Q(login)
Q(timeout)
Q(running)
Q(isrunning)
// for WLAN class
Q(WLAN)
......
......@@ -105,6 +105,7 @@ it will fallback to loading the built-in ``ujson`` module.
machine.rst
network.rst
wipy.rst
.. only:: port_esp8266
......
......@@ -27,6 +27,40 @@ For example::
data = s.recv(1000)
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
class CC3K
......@@ -178,13 +212,13 @@ For example::
Dump the WIZnet5x00 registers. Useful for debugging.
class WLAN
==========
.. _network.WLAN:
.. only:: port_esp8266
class WLAN
==========
This class provides a driver for WiFi network processor in the ESP8266. Example usage::
import network
......@@ -258,6 +292,9 @@ class WLAN
.. only:: port_wipy
class WLAN
==========
This class provides a driver for WiFi network processor in the WiPy. Example usage::
import network
......@@ -282,7 +319,7 @@ class WLAN
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.
......
: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.
......@@ -119,9 +119,10 @@ The heart beat LED
------------------
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:
......
......@@ -10,7 +10,7 @@ Quick reference for the WiPy
General board control (including sleep modes)
---------------------------------------------
See :mod:`machine`. ::
See the :mod:`machine` module::
import machine
......@@ -198,14 +198,26 @@ See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
machine.sleep()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
Heart beat LED
--------------
Telnet and FTP server
---------------------
See :ref:`network.server <network.server>` ::
from network import network
# init with new user, pass word and seconds timeout
server = server.init(login=('user', 'password'), timeout=60)
server.timeout(300) # change the timeout
server.timeout() # get the timeout
server.isrunning() # check wether the server is running or not
HeartBeat LED
-------------
See :ref:`machine.HeartBeat <machine.HeartBeat>`. ::
See :mod:`wipy`. ::
from machine import HeartBeat
import wipy
# disable the heart beat indication (you are free to use this LED connected to GP25)
HeartBeat().disable()
# enable the heart beat again
HeartBeat().enable()
wipy.heartbeat(False) # disable the heartbeat LED
wipy.heartbeat(True) # enable the heartbeat LED
wipy.heartbeat() # get the heartbeat state
......@@ -12,18 +12,18 @@ if not 'LaunchPad' in mch and not'WiPy' in mch:
server = network.server()
print(server.timeout() == 300)
print(server.running() == True)
print(server.isrunning() == True)
server.deinit()
print(server.running() == False)
print(server.isrunning() == False)
server.init(login=('test-user', 'test-password'), timeout=60)
print(server.running() == True)
print(server.isrunning() == True)
print(server.timeout() == 60)
server.deinit()
print(server.running() == False)
print(server.isrunning() == False)
server.init()
print(server.running() == True)
print(server.isrunning() == True)
try:
server.init(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment