Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
32eb4b90
Commit
32eb4b90
authored
10 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
esp8266: Move connect/disconnect from "esp" module to network.
parent
ee3fec31
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
esp8266/modesp.c
+1
-26
1 addition, 26 deletions
esp8266/modesp.c
esp8266/modnetwork.c
+33
-1
33 additions, 1 deletion
esp8266/modnetwork.c
with
34 additions
and
27 deletions
esp8266/modesp.c
+
1
−
26
View file @
32eb4b90
...
...
@@ -503,7 +503,7 @@ STATIC const mp_obj_type_t esp_socket_type = {
#define MODESP_INCLUDE_CONSTANTS (1)
static
void
error_check
(
bool
status
,
const
char
*
msg
)
{
void
error_check
(
bool
status
,
const
char
*
msg
)
{
if
(
!
status
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
msg
));
}
...
...
@@ -534,29 +534,6 @@ STATIC mp_obj_t esp_scan(mp_obj_t cb_in) {
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
esp_scan_obj
,
esp_scan
);
STATIC
mp_obj_t
esp_connect
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
struct
station_config
config
=
{{
0
}};
mp_uint_t
len
;
const
char
*
p
;
p
=
mp_obj_str_get_data
(
args
[
0
],
&
len
);
memcpy
(
config
.
ssid
,
p
,
len
);
p
=
mp_obj_str_get_data
(
args
[
1
],
&
len
);
memcpy
(
config
.
password
,
p
,
len
);
error_check
(
wifi_station_set_config
(
&
config
),
"Cannot set STA config"
);
error_check
(
wifi_station_connect
(),
"Cannot connect to AP"
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
esp_connect_obj
,
2
,
6
,
esp_connect
);
STATIC
mp_obj_t
esp_disconnect
()
{
error_check
(
wifi_station_disconnect
(),
"Cannot disconnect from AP"
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
esp_disconnect_obj
,
esp_disconnect
);
STATIC
mp_obj_t
esp_status
()
{
return
MP_OBJ_NEW_SMALL_INT
(
wifi_station_get_connect_status
());
}
...
...
@@ -616,8 +593,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_id_obj, esp_flash_id);
STATIC
const
mp_map_elem_t
esp_module_globals_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR___name__
),
MP_OBJ_NEW_QSTR
(
MP_QSTR_esp
)
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_connect
),
(
mp_obj_t
)
&
esp_connect_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_disconnect
),
(
mp_obj_t
)
&
esp_disconnect_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_scan
),
(
mp_obj_t
)
&
esp_scan_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_status
),
(
mp_obj_t
)
&
esp_status_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_mac
),
(
mp_obj_t
)
&
esp_mac_obj
},
...
...
This diff is collapsed.
Click to expand it.
esp8266/modnetwork.c
+
33
−
1
View file @
32eb4b90
...
...
@@ -32,8 +32,15 @@
#include
"py/nlr.h"
#include
"py/objlist.h"
#include
"py/runtime.h"
#include
"modnetwork.h"
#include
"netutils.h"
#include
"queue.h"
#include
"user_interface.h"
#include
"espconn.h"
#include
"ip_addr.h"
#include
"spi_flash.h"
#include
"utils.h"
void
error_check
(
bool
status
,
const
char
*
msg
);
extern
const
mp_obj_module_t
network_module
;
STATIC
mp_obj_t
get_module
()
{
...
...
@@ -41,6 +48,29 @@ STATIC mp_obj_t get_module() {
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
get_module_obj
,
get_module
);
STATIC
mp_obj_t
esp_connect
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
struct
station_config
config
=
{{
0
}};
mp_uint_t
len
;
const
char
*
p
;
p
=
mp_obj_str_get_data
(
args
[
0
],
&
len
);
memcpy
(
config
.
ssid
,
p
,
len
);
p
=
mp_obj_str_get_data
(
args
[
1
],
&
len
);
memcpy
(
config
.
password
,
p
,
len
);
error_check
(
wifi_station_set_config
(
&
config
),
"Cannot set STA config"
);
error_check
(
wifi_station_connect
(),
"Cannot connect to AP"
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
esp_connect_obj
,
2
,
6
,
esp_connect
);
STATIC
mp_obj_t
esp_disconnect
()
{
error_check
(
wifi_station_disconnect
(),
"Cannot disconnect from AP"
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
esp_disconnect_obj
,
esp_disconnect
);
STATIC
const
mp_map_elem_t
mp_module_network_globals_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR___name__
),
MP_OBJ_NEW_QSTR
(
MP_QSTR_network
)
},
// MicroPython "network" module interface requires it to contains classes
...
...
@@ -48,6 +78,8 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
// use module as a "class", and just make all methods module-global
// functions.
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_WLAN
),
(
mp_obj_t
)
&
get_module_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_connect
),
(
mp_obj_t
)
&
esp_connect_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_disconnect
),
(
mp_obj_t
)
&
esp_disconnect_obj
},
};
STATIC
MP_DEFINE_CONST_DICT
(
mp_module_network_globals
,
mp_module_network_globals_table
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment