Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 3 months ago. This question has been closed. Reason: Duplicate question
Bug reporting The socket is not readable.
I have been trying an Adafruit cc3000 shield on those platforms: Arch Max / LPCExpresso4337 / Nucleo F411RE. Each platform obviously has access to the cc3000 chip. It can read the MAC address and Firmware version, connects to the WiFi, and it even gets an IP address via DHCP from the router, which I can ping from the laptop.
The program I use to test is the cc3000_ntp_demo, slightly modified to get GPIO correct for the shield. It uses the libraries: cc3000_hostdriver_mbedsocket, NTPClient, and NVIC_set_all_priorities.
Once it comes to accessing the internet, for example getting the time from an NTP-server, it hangs there, when calling ntp_client.setTime(domain_name, port_number). The problem seems to receive data with the socket. It comes in a loop, because the socket is not readable (DEBUG enabled): .
[CC3000 : HCI TX] Command Sent : 0x1008 [CC3000 : HCI RX] Event Received : 0x1008 - BSD Select [CC3000 : SOCKET] Select on sock_fd: 0, returns 0. fdSet: 0 [CC3000 : SOCKET] The socket is not readable. _sock_fd: 0
. The voltages measured on the cc3000 shield power pins look fine: 5.03V and 3.32V.
The output looks like: .
mbed cc3000 NTP client demo. Initialize the interface with DHCP... Read from cc3000... Firmware version: 1.32 MAC address : 08:00:28:57:A0:5A WiFi parameters: SSID : Prakjaroen Phrase : A4B5C6D7E8F9 Security : WPA2 Bring the interface up... IP : 192.168.2.123 Netmask : 255.255.255.0 Gateway : 192.168.2.1 MAC : 0.0.0.0 Connected : 1 DHCP : 1 Enabled : 1 Reading time... [CC3000 : HCI TX] Command Sent : 0x1001 [CC3000 : HCI RX] Event Received : 0x1001 - Socket [CC3000 : SOCKET] Socket created (fd: 0 type: 2, protocol: 17) [CC3000 : HCI TX] Command Sent : 0x1002 [CC3000 : HCI RX] Event Received : 0x1002 - Bind [CC3000 : HCI TX] Command Sent : 0x1010 [CC3000 : HCI RX] Event Received : 0x1010 - Get Hostname [CC3000 : SOCKET] remote host address (string): 134.0.16.1 [CC3000 : SOCKET] remote host address from s_addr : 134.0.16.1 [CC3000 : SOCKET] port: 123 [CC3000 : HCI RX] Event Received : 0x100F - Send To [CC3000 : HCI TX] Command Sent : 0x1008 [CC3000 : HCI RX] Event Received : 0x1008 - BSD Select [CC3000 : SOCKET] Select on sock_fd: 0, returns 0. fdSet: 0 [CC3000 : SOCKET] The socket is not readable. _sock_fd: 0 [CC3000 : HCI TX] Command Sent : 0x1008 [CC3000 : HCI RX] Event Received : 0x1008 - BSD Select [CC3000 : SOCKET] Select on sock_fd: 0, returns 0. fdSet: 0 [CC3000 : SOCKET] The socket is not readable. _sock_fd: 0
.
Note: "The socket is not readable. _sock_fd: 0" .
Main.cpp: .
/* mbed Microcontroller Library * Copyright (c) 2006-2013 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "cc3000.h" #include "main.h" #include "NTPClient.h" #define CC3000_IRQ D3 // (D3) #define CC3000_EN D5 // (D5) #define CC3000_CS D10 // (D10) #define CC3000_MOSI D11 // (D11) #define CC3000_MISO D12 // (D12) #define CC3000_SCLK D13 // (D13) #define SSID "Prakjaroen" #define PHRASE "A4B5C6D7E8F9" #define SECURITY WPA2 #define IP "192.168.2.165" #define MASK "255.255.255.0" #define GW "192.168.2.1" #define DHCP 0 #define STATIC_IP 1 #define IP_INIT DHCP using namespace mbed_cc3000; // cc3000 wifi(irq, en, cs, SPI(mosi, miso, sclk), SSID, PHRASE, WPA2, false); // +5V VCC 5V +5V // GND GND GND GND // D8 INT Interrupt PA_9 // D9 EN WiFi Enable PC_7 // D10 CS SPI Chip Select PB_6 // D11 MOSI SPI MOSI PA_7 // D12 MISO SPI MISO PA_6 // D13 SCK SPI Clock PA_5 /* cc3000 module declaration specific for user's board. Check also init() */ #if (MY_BOARD == WIGO) cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), SSID, PHRASE, SECURITY, false); Serial pc(USBTX, USBRX); #elif (MY_BOARD == WIFI_DIPCORTEX) cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), SSID, PHRASE, SECURITY, false); Serial pc(UART_TX, UART_RX); #elif (MY_BOARD == MBED_BOARD_EXAMPLE) cc3000 wifi(CC3000_IRQ, CC3000_EN, CC3000_CS, SPI(CC3000_MOSI, CC3000_MISO, CC3000_SCLK), SSID, PHRASE, SECURITY, false); //SparkFun Board on Arduino pin definitions //Serial pc(USBTX, USBRX); Serial pc(P2_10, P2_11); // TX, RX #else #endif // array to store RM parameters from EEPROM unsigned char cRMParamsFromEeprom[128]; // array to store MAC address from EEPROM unsigned char cMacFromEeprom[6]; /** * \brief NTP client demo * \param none * \return int */ int main() { uint8_t firmware_ver[2]; signed char mac_status = -1; unsigned char FW_status = 1; init(); /* board dependent init */ pc.baud(230400); printf("\r\n\r\nmbed cc3000 NTP client demo. \r\n"); #if (IP_INIT == STATIC_IP) printf("Initialize the interface with a static IP address...\r\n"); wifi.init(IP, MASK, GW); #else printf("Initialize the interface with DHCP...\r\n"); wifi.init(); #endif /* STM32F10X_CL */ printf("Read from cc3000...\r\n"); // Read Firmware Version and MAC Address FW_status = wifi.read_sp_version(firmware_ver); // read actual Firmware version if(FW_status == 0){ printf("Firmware version: %d.%d\n\r",firmware_ver[0],firmware_ver[1]); mac_status = wifi.get_mac_address(cMacFromEeprom); if(mac_status == 0){ printf("MAC address : "); for(int i = 0; i < 6; i++) { printf("%02X", cMacFromEeprom[i]); if (i < 5) printf(":"); } printf("\r\n"); } } else { printf("ERROR: CC3000 not found - check connections !\r\n"); } // WiFi parameters printf("WiFi parameters:\r\n"); printf("SSID : %s\r\n", SSID); printf("Phrase : %s\r\n", PHRASE); printf("Security : "); if (SECURITY == 0) printf("NONE"); if (SECURITY == 1) printf("WEP"); if (SECURITY == 2) printf("WPA"); if (SECURITY == 3) printf("WPA2"); printf("\r\n"); wait(1.0); // Connect to WiFi printf("Bring the interface up...\r\n"); if (wifi.connect(30000) == -1) { printf("ERROR: Failed to connect. Please verify connection details and try again.\r\n"); } char *ip = wifi.getIPAddress(); char *mask = wifi.getNetworkMask(); char *gate = wifi.getGateway(); char *mac = wifi.getMACAddress(); bool conn = wifi.is_connected(); bool dhcp = wifi.is_dhcp_configured(); bool enabled = wifi.is_enabled(); printf("IP : %s\r\n", ip); printf("Netmask : %s\r\n", mask); printf("Gateway : %s\r\n", gate); printf("MAC : %s\r\n", mac); printf("Connected : %d\r\n", conn); printf("DHCP : %d\r\n", dhcp); printf("Enabled : %d\r\n", enabled); wait(1.0); // Read time from server NTPClient ntp_client; // NTP Server Parameters char* domain_name = "0.uk.pool.ntp.org"; int port_number = 123; // Read time from server printf("Reading time...\r\n"); if (ntp_client.setTime(domain_name, port_number) == 0) { printf("Set time successfully.\r\n"); time_t ct_time; char time_buffer[80]; ct_time = time(NULL) + 7200; // Summer time - Convert to Europe/Amsterdam Time set_time(ct_time); strftime(time_buffer, 80, "%a %d-%b-%Y %T\r\n", localtime(&ct_time)); printf("Time : %s\r\n", time_buffer); } else { printf("ERROR: Failed set time.\r\n"); } printf("Demo completed.\r\n"); wifi.disconnect(); }
Question relating to:
1 Answer
9 years, 3 months ago.
Jack, I can give you a quick fix. Open NTPClient.cpp, find
m_sock.bind(0); Bind to a random port
and change it to
m_sock.bind(123); Bind to a random port
Let me know if it works for you.
This reminds me there's an issue for this. I left a note in the cookbook (I might not have included that in the NTP code example, wchih we can add there ).
This is the comment: There's a known issue with a bind to any port (0) for cc3000. Please set the bind address inside NTP client to any port except 0.
posted by 18 Aug 2015Here's a question (I explained NTP mbed client and issue I was having) which has a solution proposed, but not enough, and might have not been fixed since. http://e2e.ti.com/support/wireless_connectivity/f/851/p/247829/1040312
posted by 18 Aug 2015@Martin Please update NTPClient so that the" out of the box experience" works.
posted by 18 Aug 2015Hi David, thank you for the quick response. That works very well!
Off-Topic: when the cc3000 is connected to the LPCXpresso4337, which is a fast board, it often hangs anywhere, while communicating with the cc3000. Maybe this can be verified by somebody else too? Supply voltages on the shield are fine.
posted by 18 Aug 2015