Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: M2XStreamClient SocketModem jsonlite mbed
Fork of STM32_MTS_Wifi_Connect_M2X by
Revision 17:e54be812a3b3, committed 2014-09-05
- Comitter:
- jb8414
- Date:
- Fri Sep 05 02:28:21 2014 +0000
- Parent:
- 16:921fec88838d
- Commit message:
- Port for STM411 board
Changed in this revision
--- a/M2XStreamClient.lib Tue Aug 19 19:12:11 2014 +0000 +++ b/M2XStreamClient.lib Fri Sep 05 02:28:21 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/joe_tijerina/code/M2XStreamClient/#cf982472fc7c +http://mbed.org/users/joe_tijerina/code/M2XStreamClient/#6fbc104d1321
--- a/SocketModem.lib Tue Aug 19 19:12:11 2014 +0000 +++ b/SocketModem.lib Fri Sep 05 02:28:21 2014 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/teams/Multi-Hackers/code/SocketModem/#e0a437f61854 +https://mbed.org/teams/Multi-Hackers/code/SocketModem/#9a2c7ed27744
--- a/main.cpp Tue Aug 19 19:12:11 2014 +0000
+++ b/main.cpp Fri Sep 05 02:28:21 2014 +0000
@@ -1,10 +1,12 @@
#include "mbed.h"
#include "M2XStreamClient.h"
-#include "MTSSerial.h"
-#include "Wifi.h"
#include "include_me.h"
#include "math.h"
+// set to 1 for cellular shield board
+// set to 0 for wifi shield board
+#define CELL_SHIELD 1
+
using namespace mts;
/* This example shows how to do a basic connectivity test to AT&T M2X Cloud
@@ -14,10 +16,10 @@
using namespace mts;
-const char key[] = "your_api_key"; // Replace with your M2X API key
-const char feed[] = "your_feed_id"; // Replace with your blueprint Feed ID
-const char stream[] = "your_stream_name"; // Replace with your stream name
-char name[] = "your_device_location_name"; // Name of current location of datasource
+const char key[] = "<key>"; // Replace with your M2X API key
+const char feed[] = "<feed>"; // Replace with your blueprint Feed ID
+const char stream[] = "<stream>"; // Replace with your stream name
+char name[] = "<location>"; // Name of current location of datasource
double latitude = 30.3748076;
double longitude = -97.7386896; // You can also read those values from a GPS
@@ -59,10 +61,66 @@
float temperature_f;
//Set the network parameters
- std::string ssid = "your_wifi_ssid";
- std::string securityKey = "your_wifi_passphrase";
+ std::string ssid = "<ssid>";
+ std::string securityKey = "<password>";
Wifi::SecurityType securityType = Wifi::WPA2;
+ printf("starting\n\r");
+
+#if CELL_SHIELD
+ MTSSerialFlowControl* serial = new MTSSerialFlowControl(PA_9, PA_10, PA_1, PA_0);
+ serial->baud(115200);
+ printf("serialflow ok\n\r");
+ Transport::setTransport(Transport::CELLULAR);
+ Cellular* cell = Cellular::getInstance();
+ cell->init(serial, PB_5, PA_8); //DCD and DTR pins for STM411
+
+ int max_tries = 5;
+ int i;
+ std::string apn = "wap.cingular"; // set to the appropriate APN (i.e. "m2m.com.attz" for M2X SIMs, wap.cingular)
+
+ i = 0;
+ while (i++ < max_tries) {
+ if (cell->getRegistration() == Cellular::REGISTERED) {
+ printf("registered with tower\n\r");
+ break;
+ } else if (i >= max_tries) {
+ printf("failed to register with tower\n\r");
+ } else {
+ wait(3);
+ }
+ }
+
+ printf("signal strength: %d\n\r", cell->getSignalStrength());
+
+ i = 0;
+ printf("setting APN to %s\n\r", apn.c_str());
+ while (i++ < max_tries) {
+ if (cell->setApn(apn) == SUCCESS) {
+ printf("successfully set APN\n\r");
+ break;
+ } else if (i >= max_tries) {
+ printf("failed to set APN\n\r");
+ } else {
+ wait(1);
+ }
+ }
+
+ i = 0;
+ printf("bringing up PPP link\n\r");
+ while (i++ < max_tries) {
+ if (cell->connect()) {
+ printf("PPP link is up\n\r");
+ break;
+ } else if (i >= max_tries) {
+ printf("failed to bring PPP link up\n\r");
+ } else {
+ wait(1);
+ }
+ }
+#else
+ // WiFi shield
+
//Wait for wifi module to boot up
for (int i = 10; i >= 0; i = i - 2) {
wait(2);
@@ -70,7 +128,7 @@
}
//Setup serial interface to WiFi module
- MTSSerial* serial = new MTSSerial(D8, D2, 256, 4096);
+ MTSSerial* serial = new MTSSerial(PA_9, PA_10, 256, 4096);
serial->baud(9600);
Transport::setTransport(Transport::WIFI);
@@ -88,10 +146,12 @@
}
printf("Connect: Success\r\n");
printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+
+
printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed");
wait(1);
-
+#endif
// Initialize the M2X client
Client client;
--- a/mbed.bld Tue Aug 19 19:12:11 2014 +0000 +++ b/mbed.bld Fri Sep 05 02:28:21 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file
