Yonariel Hernandez
/
Proyecto-Final_copy_petey
kio
source/network-helper.h@2:4745484bc533, 2021-08-05 (annotated)
- Committer:
- yonaetworks
- Date:
- Thu Aug 05 01:28:42 2021 +0000
- Revision:
- 2:4745484bc533
- Parent:
- 0:29132844de96
funciona URL post/get desde MBEDOS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yonaetworks | 0:29132844de96 | 1 | #ifndef _MBED_HTTP_EXAMPLE_H_ |
yonaetworks | 0:29132844de96 | 2 | #define _MBED_HTTP_EXAMPLE_H_ |
yonaetworks | 0:29132844de96 | 3 | |
yonaetworks | 0:29132844de96 | 4 | #include "mbed.h" |
yonaetworks | 0:29132844de96 | 5 | #include "NetworkInterface.h" |
yonaetworks | 0:29132844de96 | 6 | |
yonaetworks | 0:29132844de96 | 7 | /** |
yonaetworks | 0:29132844de96 | 8 | * Connect to the network using the default networking interface, |
yonaetworks | 0:29132844de96 | 9 | * you can also swap this out with a driver for a different networking interface |
yonaetworks | 0:29132844de96 | 10 | * if you use WiFi: see mbed_app.json for the credentials |
yonaetworks | 0:29132844de96 | 11 | */ |
yonaetworks | 0:29132844de96 | 12 | NetworkInterface *connect_to_default_network_interface() { |
yonaetworks | 0:29132844de96 | 13 | printf("[NWKH] Connecting to network...\n"); |
yonaetworks | 0:29132844de96 | 14 | |
yonaetworks | 0:29132844de96 | 15 | NetworkInterface* network = NetworkInterface::get_default_instance(); |
yonaetworks | 0:29132844de96 | 16 | |
yonaetworks | 0:29132844de96 | 17 | if (!network) { |
yonaetworks | 0:29132844de96 | 18 | printf("[NWKH] No network interface found, select an interface in 'network-helper.h'\n"); |
yonaetworks | 0:29132844de96 | 19 | return NULL; |
yonaetworks | 0:29132844de96 | 20 | } |
yonaetworks | 0:29132844de96 | 21 | |
yonaetworks | 0:29132844de96 | 22 | nsapi_error_t connect_status = network->connect(); |
yonaetworks | 0:29132844de96 | 23 | |
yonaetworks | 0:29132844de96 | 24 | if (connect_status != NSAPI_ERROR_OK) { |
yonaetworks | 0:29132844de96 | 25 | printf("[NWKH] Failed to connect to network (%d)\n", connect_status); |
yonaetworks | 0:29132844de96 | 26 | return NULL; |
yonaetworks | 0:29132844de96 | 27 | } |
yonaetworks | 0:29132844de96 | 28 | |
yonaetworks | 0:29132844de96 | 29 | printf("[NWKH] Connected to the network\n"); |
yonaetworks | 0:29132844de96 | 30 | printf("[NWKH] IP address: %s\n", network->get_ip_address()); |
yonaetworks | 0:29132844de96 | 31 | return network; |
yonaetworks | 0:29132844de96 | 32 | } |
yonaetworks | 0:29132844de96 | 33 | |
yonaetworks | 0:29132844de96 | 34 | #endif // _MBED_HTTP_EXAMPLE_H_ |