Version of easy-connect with the u-blox cellular platforms C027 and C030 added.
esp8266-driver/TESTS/net/connectivity/main.cpp@6:304d3ba87a01, 2017-11-03 (annotated)
- Committer:
- RobMeades
- Date:
- Fri Nov 03 13:01:23 2017 +0000
- Revision:
- 6:304d3ba87a01
- Parent:
- 0:19aa55d66228
Add comment concerning N2XX baud rate.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-ublox | 0:19aa55d66228 | 1 | #include "mbed.h" |
group-ublox | 0:19aa55d66228 | 2 | #include "greentea-client/test_env.h" |
group-ublox | 0:19aa55d66228 | 3 | #include "unity.h" |
group-ublox | 0:19aa55d66228 | 4 | #include "utest.h" |
group-ublox | 0:19aa55d66228 | 5 | |
group-ublox | 0:19aa55d66228 | 6 | #include "ESP8266Interface.h" |
group-ublox | 0:19aa55d66228 | 7 | |
group-ublox | 0:19aa55d66228 | 8 | using namespace utest::v1; |
group-ublox | 0:19aa55d66228 | 9 | |
group-ublox | 0:19aa55d66228 | 10 | #ifndef MBED_CFG_ESP8266_TX |
group-ublox | 0:19aa55d66228 | 11 | #define MBED_CFG_ESP8266_TX D1 |
group-ublox | 0:19aa55d66228 | 12 | #endif |
group-ublox | 0:19aa55d66228 | 13 | |
group-ublox | 0:19aa55d66228 | 14 | #ifndef MBED_CFG_ESP8266_RX |
group-ublox | 0:19aa55d66228 | 15 | #define MBED_CFG_ESP8266_RX D0 |
group-ublox | 0:19aa55d66228 | 16 | #endif |
group-ublox | 0:19aa55d66228 | 17 | |
group-ublox | 0:19aa55d66228 | 18 | #ifndef MBED_CFG_ESP8266_DEBUG |
group-ublox | 0:19aa55d66228 | 19 | #define MBED_CFG_ESP8266_DEBUG false |
group-ublox | 0:19aa55d66228 | 20 | #endif |
group-ublox | 0:19aa55d66228 | 21 | |
group-ublox | 0:19aa55d66228 | 22 | #define STRINGIZE(x) STRINGIZE2(x) |
group-ublox | 0:19aa55d66228 | 23 | #define STRINGIZE2(x) #x |
group-ublox | 0:19aa55d66228 | 24 | |
group-ublox | 0:19aa55d66228 | 25 | |
group-ublox | 0:19aa55d66228 | 26 | // Bringing the network up and down |
group-ublox | 0:19aa55d66228 | 27 | template <int COUNT> |
group-ublox | 0:19aa55d66228 | 28 | void test_bring_up_down() { |
group-ublox | 0:19aa55d66228 | 29 | ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG); |
group-ublox | 0:19aa55d66228 | 30 | net.set_credentials(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS)); |
group-ublox | 0:19aa55d66228 | 31 | |
group-ublox | 0:19aa55d66228 | 32 | for (int i = 0; i < COUNT; i++) { |
group-ublox | 0:19aa55d66228 | 33 | int err = net.connect(); |
group-ublox | 0:19aa55d66228 | 34 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 35 | |
group-ublox | 0:19aa55d66228 | 36 | printf("MBED: IP Address %s\r\n", net.get_ip_address()); |
group-ublox | 0:19aa55d66228 | 37 | printf("MBED: Netmask %s\r\n", net.get_netmask()); |
group-ublox | 0:19aa55d66228 | 38 | printf("MBED: Gateway %s\r\n", net.get_gateway()); |
group-ublox | 0:19aa55d66228 | 39 | TEST_ASSERT(net.get_ip_address()); |
group-ublox | 0:19aa55d66228 | 40 | TEST_ASSERT(net.get_netmask()); |
group-ublox | 0:19aa55d66228 | 41 | TEST_ASSERT(net.get_gateway()); |
group-ublox | 0:19aa55d66228 | 42 | |
group-ublox | 0:19aa55d66228 | 43 | UDPSocket udp; |
group-ublox | 0:19aa55d66228 | 44 | err = udp.open(&net); |
group-ublox | 0:19aa55d66228 | 45 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 46 | err = udp.close(); |
group-ublox | 0:19aa55d66228 | 47 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 48 | |
group-ublox | 0:19aa55d66228 | 49 | TCPSocket tcp; |
group-ublox | 0:19aa55d66228 | 50 | err = tcp.open(&net); |
group-ublox | 0:19aa55d66228 | 51 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 52 | err = tcp.close(); |
group-ublox | 0:19aa55d66228 | 53 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 54 | |
group-ublox | 0:19aa55d66228 | 55 | err = net.disconnect(); |
group-ublox | 0:19aa55d66228 | 56 | TEST_ASSERT_EQUAL(0, err); |
group-ublox | 0:19aa55d66228 | 57 | } |
group-ublox | 0:19aa55d66228 | 58 | } |
group-ublox | 0:19aa55d66228 | 59 | |
group-ublox | 0:19aa55d66228 | 60 | |
group-ublox | 0:19aa55d66228 | 61 | // Test setup |
group-ublox | 0:19aa55d66228 | 62 | utest::v1::status_t test_setup(const size_t number_of_cases) { |
group-ublox | 0:19aa55d66228 | 63 | GREENTEA_SETUP(120, "default_auto"); |
group-ublox | 0:19aa55d66228 | 64 | return verbose_test_setup_handler(number_of_cases); |
group-ublox | 0:19aa55d66228 | 65 | } |
group-ublox | 0:19aa55d66228 | 66 | |
group-ublox | 0:19aa55d66228 | 67 | Case cases[] = { |
group-ublox | 0:19aa55d66228 | 68 | Case("Bringing the network up and down", test_bring_up_down<1>), |
group-ublox | 0:19aa55d66228 | 69 | Case("Bringing the network up and down twice", test_bring_up_down<2>), |
group-ublox | 0:19aa55d66228 | 70 | }; |
group-ublox | 0:19aa55d66228 | 71 | |
group-ublox | 0:19aa55d66228 | 72 | Specification specification(test_setup, cases); |
group-ublox | 0:19aa55d66228 | 73 | |
group-ublox | 0:19aa55d66228 | 74 | int main() { |
group-ublox | 0:19aa55d66228 | 75 | return !Harness::run(specification); |
group-ublox | 0:19aa55d66228 | 76 | } |