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: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp
- Committer:
- xinlei
- Date:
- 2015-03-16
- Revision:
- 90:0525121f307e
- Parent:
- 89:8ab476939897
- Child:
- 91:423177e8a401
File content as of revision 90:0525121f307e:
#include <stdio.h>
#include "mbed.h"
#include "rtos.h"
#include "MDM.h"
#include "GPS.h"
#include "DeviceInfo.h"
#include "DeviceMemory.h"
#include "MbedAgent.h"
#include "GPSTracker.h"
#include "DeviceConfiguration.h"
#include "logging.h"
/**
* SIM PIN. Null for no pin.
*/
#define SIM_PIN NULL
/**
* SIM GPRS login data. Leave commented out for automatic setting.
*/
//#define SIM_APN ""
//#define SIM_USER ""
//#define SIM_PASS ""
unsigned short getMNCLen(const char *imsi) {
if (strncmp(imsi, "310", 3) != 0) // Non American ISMI
return 2;
else
return 3;
}
int main()
{
MDMParser::DevStatus devStatus;
uint8_t status = 0;
MDMRtos<MDMSerial> mdm;
GPSI2C gps;
DeviceIO io(gps);
DigitalIn joystickUp(A2);
DigitalIn joystickDown(A3);
if (joystickUp) {
setLevel(A_DEBUG);
mdm.setDebug(3);
printf("Enable debug mode.\r\n");
} else {
setLevel(A_NONE);
mdm.setDebug(-1);
}
io.lcdPrint("Mbed Agent V2.1rc1", MBED_AGENT_HOST);
if (!mdm.init(SIM_PIN, &devStatus)) {
status = 1;
io.lcdPrint("Modem Init Failure", "No SIM card found", "Or SIM has PIN code");
} else if (!gps.init()) {
status = 2;
io.lcdPrint("GPS Init Failure");
}
if (status != 0) {
mdm.disconnect();
mdm.powerOff();
return 1;
}
DeviceInfo deviceInfo(mdm, devStatus);
DeviceMemory deviceMemory(mdm);
if (io.resetButtonPressed()) {
io.lcdPrint("Factory Reset");
if (deviceMemory.resetPlatformCredentials()) {
// io.deviceFeedback().beepSuccess();
io.lcdPrint("Reset Success");
}
else {
// io.deviceFeedback().beepFailure();
io.lcdPrint("Reset Failure");
}
Thread::wait(1000);
return 0;
}
io.lcdPrint("Register Network...", "IMEI", devStatus.imei);
if (!mdm.registerNet()) {
io.lcdPrint("No Network Coverage");
goto error;
}
io.lcdPrint("Join Network");
#ifdef SIM_APN
if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) {
#else
if (mdm.join() == NOIP) {
#endif
char s[8] = "unknown";
const char *p = devStatus.imsi;
if (p) {
snprintf(s, sizeof(s), "%.*s-%.*s", 3, p, getMNCLen(p), p+3);
}
io.lcdPrint("Wrong APN settting", "MCC-MNC:", s);
goto error;
}
{
MbedAgent agent(io, mdm, deviceInfo, deviceMemory);
io.lcdPrint("Agent Init");
if (!agent.init()) {
io.lcdPrint("Agent Init Failure", "Debug via serial port");
goto error;
}
uint8_t tries = 3;
do {
io.lcdPrint("Agent Run");
if (agent.run())
break;
} while (--tries > 0);
if (tries == 0) {
io.lcdPrint("Integration/Config Failure");
goto error;
}
}
mdm.disconnect();
mdm.powerOff();
return 0;
error:
mdm.disconnect();
mdm.powerOff();
return 1;
}

Cumulocity