Hiya. I’m having a weird issue I don’t understand.
I’m reverse-engineering an automotive GPS tracker device based on an STM32F103VCT6 that I accidentally bricked (long story).
I’ve managed to activate all the peripherals however it is using HSI and LSI as for some reason it isn’t keen on activating the xtal oscillators (both are present)
I’ve managed to interface with the 3G module, get it connected to PPP etc. My problem lays with the Socket network layer.
Neither UDP nor TCP sockets will connect and send data.
- DNS lookup succeeds
- Socket reports connect success
- Packet capture on the ‘remote’ end (my own webserver) shows the TCP handshake occurring
- Attempt to send any data fails (not received by server, as in example below) or times out (HTTPRequest class)
Any hints? I’m stumped. Main function is below.
int main()
{
//----------------------------------ORIGINAL CODE--------------------------------//
Thread tNorm(osPriorityNormal);
DO_AuxPwr = 1;
Modem_ONOFF = 0;
U_GPS.set_blocking(false);
tNorm.start(callback(&npQueue, &EventQueue::dispatch_forever));
npQueue.call_every(500ms, blinkLed);
Modem_ONOFF = 1;
//-------------------------------CELLULAR EXAMPLE--------------------------------//
printf("Establishing connection\n");
#if MBED_CONF_MBED_TRACE_ENABLE
trace_open();
#else
dot_thread.start(dot_event);
#endif // #if MBED_CONF_MBED_TRACE_ENABLE
iface = CellularContext::get_default_instance();
MBED_ASSERT(iface);
// sim pin, apn, credentials and possible plmn are taken automatically from json when using NetworkInterface::set_default_parameters()
iface->set_default_parameters();
nsapi_error_t retcode = NSAPI_ERROR_NO_CONNECTION;
/* Attempt to connect to a cellular network */
if (do_connect() == NSAPI_ERROR_OK) {
printf("\n----- Setting up TCP connection -----\n");
TCPSocket* socket = new TCPSocket();
SocketAddress address;
printf("Looking up hostname\n");
nsapi_error_t dns_result = iface->gethostbyname("<<HOSTNAME>>",&address);
if(dns_result != 0){
printf("DNS Failed...\n");
} else {
printf("Got IP: %s\n", address.get_ip_address());
}
printf("Done...\n");
address.set_port(80);
nsapi_error_t open_result = socket->open(iface);
if (open_result != 0) {
printf("Opening TCPSocket failed... %d\n", open_result);
return 1;
}
nsapi_error_t connect_result = socket->connect(address);
if (connect_result != 0) {
printf("Connecting over TCPSocket failed... %d\n", connect_result);
return 1;
} else {
printf("Connected\n");
}
socket->send("GET / HTTP/1.0\n\n", 19);
socket->close();
}
if (iface->disconnect() != NSAPI_ERROR_OK) {
print_function("\n\n Disconnect failed.\n\n");
}
if (retcode == NSAPI_ERROR_OK) {
print_function("\n\nSuccess. Exiting \n\n");
} else {
print_function("\n\nFailure. Exiting \n\n");
}
#if MBED_CONF_MBED_TRACE_ENABLE
trace_close();
#else
dot_thread.terminate();
#endif // #if MBED_CONF_MBED_TRACE_ENABLE
return 0;
}