Version of easy-connect with the u-blox cellular platforms C027 and C030 added.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "greentea-client/test_env.h" 00003 #include "unity.h" 00004 #include "utest.h" 00005 00006 #include "ESP8266Interface.h" 00007 00008 using namespace utest::v1; 00009 00010 #ifndef MBED_CFG_ESP8266_TX 00011 #define MBED_CFG_ESP8266_TX D1 00012 #endif 00013 00014 #ifndef MBED_CFG_ESP8266_RX 00015 #define MBED_CFG_ESP8266_RX D0 00016 #endif 00017 00018 #ifndef MBED_CFG_ESP8266_DEBUG 00019 #define MBED_CFG_ESP8266_DEBUG false 00020 #endif 00021 00022 #define STRINGIZE(x) STRINGIZE2(x) 00023 #define STRINGIZE2(x) #x 00024 00025 00026 // Bringing the network up and down 00027 template <int COUNT> 00028 void test_bring_up_down() { 00029 ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG); 00030 net.set_credentials(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS)); 00031 00032 for (int i = 0; i < COUNT; i++) { 00033 int err = net.connect(); 00034 TEST_ASSERT_EQUAL(0, err); 00035 00036 printf("MBED: IP Address %s\r\n", net.get_ip_address()); 00037 printf("MBED: Netmask %s\r\n", net.get_netmask()); 00038 printf("MBED: Gateway %s\r\n", net.get_gateway()); 00039 TEST_ASSERT(net.get_ip_address()); 00040 TEST_ASSERT(net.get_netmask()); 00041 TEST_ASSERT(net.get_gateway()); 00042 00043 UDPSocket udp; 00044 err = udp.open(&net); 00045 TEST_ASSERT_EQUAL(0, err); 00046 err = udp.close(); 00047 TEST_ASSERT_EQUAL(0, err); 00048 00049 TCPSocket tcp; 00050 err = tcp.open(&net); 00051 TEST_ASSERT_EQUAL(0, err); 00052 err = tcp.close(); 00053 TEST_ASSERT_EQUAL(0, err); 00054 00055 err = net.disconnect(); 00056 TEST_ASSERT_EQUAL(0, err); 00057 } 00058 } 00059 00060 00061 // Test setup 00062 utest::v1::status_t test_setup(const size_t number_of_cases) { 00063 GREENTEA_SETUP(120, "default_auto"); 00064 return verbose_test_setup_handler(number_of_cases); 00065 } 00066 00067 Case cases[] = { 00068 Case("Bringing the network up and down", test_bring_up_down<1>), 00069 Case("Bringing the network up and down twice", test_bring_up_down<2>), 00070 }; 00071 00072 Specification specification(test_setup, cases); 00073 00074 int main() { 00075 return !Harness::run(specification); 00076 }
Generated on Tue Jul 12 2022 15:14:29 by 1.7.2