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.
10 years, 5 months ago.
Could not connect to the network.
Hi Sir, I have tried the main.cpp of Seed_GRPS_Shield. I could not connect to the network.
The way i connect is: p9(TX) of mbed to D0(RX) of Seeed Studio GPRS Shield V2.0 and p10(RX) of mbed to D1(TX) of Seeed Studio GPRS Shield V2.0.
VU of(5.0v USB Out) Mbed to VIN of GPRS Shield, and GND to GND.
I used Starhub MaxMobile Prepaid Card. (https://www.starhub.com/business/support/internet-ip-solutions/faqs/prepaid-mobile-broadband.html)
I print out in putty terminal and it printed as follow:
Could not connect to network. Retrying!
May I know what would be the problems?
Thank you so much:D
Regards Dorothy
Question relating to:
1 Answer
10 years, 5 months ago.
hello, can you show me your main.cpp?
Hi I used your main.cpp. Thank you so much for your superfast reply.
Here is the main.cpp that I used:
- include "mbed.h"
- include "GPRSInterface.h"
/ On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication.
- You can use an LCD display to print the values or store them on an SD card etc.
- / Serial pc(USBTX, USBRX);
/**
- D1 - TX pin (RX on the WiFi side)
- D0 - RX pin (TX on the WiFi side)
- 115200 - Baud rate
- "apn" - APN name
- "username" - APN username
- "password" - APN passowrd
- / GPRSInterface eth(D1, D0, 115200, "eshppd", "NULL", "NULL");
int main() { wait(3);
Initialize the interface.
If no param is passed to init() then DHCP will be used on connect()
int s = eth.init();
if (s != NULL) {
printf(">>> Could not initialise. Halting!\n");
exit(0);
}
printf(">>> Get IP address...\n");
while (1) {
s = eth.connect(); Connect to network
if (s == false || s < 0) {
printf(">>> Could not connect to network. Retrying!\n");
wait(3);
} else {
break;
}
}
printf(">>> Got IP address: %s\n", eth.getIPAddress());
Prepare the http request to mbed.org
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
TCPSocketConnection sock;
sock.connect("mbed.org", 80);
sock.send_all(http_cmd, sizeof(http_cmd)-1);
printf(">>> Sent request to mbed.org\n");
Read the response
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
}
sock.close();
Disconnect from network
eth.disconnect();
return 0;
}
APN that I used is MaxMobile Prepaid Card APN.
I found this APN from this website:
https://www.starhub.com/business/support/internet-ip-solutions/faqs/prepaid-mobile-broadband.html
posted by 12 Jun 2014
main.cpp that I used:
/ On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication.
/**
int main() {
wait(3);
Initialize the interface. If no param is passed to init() then DHCP will be used on connect() int s = eth.init(); if (s != NULL) { printf(">>> Could not initialise. Halting!\n"); exit(0); }
printf(">>> Get IP address...\n"); while (1) { s = eth.connect(); Connect to network
if (s == false || s < 0) { printf(">>> Could not connect to network. Retrying!\n"); wait(3); } else { break; } } printf(">>> Got IP address: %s\n", eth.getIPAddress());
Prepare the http request to mbed.org char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; TCPSocketConnection sock; sock.connect("mbed.org", 80); sock.send_all(http_cmd, sizeof(http_cmd)-1); printf(">>> Sent request to mbed.org\n");
Read the response char buffer[300]; int ret; while (true) { ret = sock.receive(buffer, sizeof(buffer)-1); if (ret <= 0) break; buffer[ret] = '\0'; printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer); } sock.close();
Disconnect from network eth.disconnect(); return 0; }
posted by Dorothy Luai 12 Jun 2014your main.cpp seems not correct, please refer to https://mbed.org/users/lawliet/code/Seeed_GPRS_Library_HelloWorld/file/46f9e36be3fa/main.cpp ,thanks
posted by wei zou 12 Jun 2014