Port to C027 (using AppShield and Cellular)
Dependencies: C027_Support C12832 LM75B MMA7660 MQTT mbed-rtos mbed
Dependents: TCU-POC_BACK_WORKING
Fork of IBMIoTClientEthernetExample by
Diff: main.cpp
- Revision:
- 13:6a0af5deb2db
- Parent:
- 12:d6b94e8051b0
- Child:
- 14:6f36d75b3917
diff -r d6b94e8051b0 -r 6a0af5deb2db main.cpp --- a/main.cpp Thu Mar 12 12:31:06 2015 +0000 +++ b/main.cpp Fri Mar 13 06:23:30 2015 +0000 @@ -45,24 +45,42 @@ #define MQTT_MAX_PACKET_SIZE 250 -#if defined(TARGET_UBLOX_C027) -# warning "Compiling for mbed C027" -# include "C027.h" -#elif defined(TARGET_LPC1768) -# warning "Compiling for mbed LPC1768" -# include "LPC1768.h" -#elif defined(TARGET_K64F) -# warning "Compiling for mbed K64F" -# include "K64F.h" -#endif +C12832 lcd(D11, D13, D12, D7, D10); +PwmOut r(D5); +PwmOut g(D9); +PwmOut b(D8); +DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); +MMA7660 MMA(D14, D15); +LM75B sensor(D14,D15); +DigitalIn Up(A2); DigitalIn Down(A3); DigitalIn Left(A4); DigitalIn Right(A5); DigitalIn Click(D4); +AnalogIn ain1 (A0); AnalogIn ain2 (A1); + +#define LED2_OFF 0 +#define LED2_ON 1 + +#define DEFAULT_TYPE_NAME "iotsample-mbed-c027" -#ifdef USE_CELLULAR -# define MQTT_CLIENT_TYPE MQTTSocket -# include "MQTTSocket.h" -#else -# define MQTT_CLIENT_TYPE MQTTEthernet -# include "MQTTEthernet.h" -#endif + //------------------------------------------------------------------------------------ +// You need to configure these cellular modem / SIM parameters. +// These parameters are ignored for LISA-C200 variants and can be left NULL. +//------------------------------------------------------------------------------------ +# include "MDM.h" +//! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. +# define SIMPIN NULL +/*! The APN of your network operator SIM, sometimes it is "internet" check your + contract with the network operator. You can also try to look-up your settings in + google: https://www.google.de/search?q=APN+list */ +# define APN NULL +//! Set the user name for your APN, or NULL if not needed +# define USERNAME NULL +//! Set the password for your APN, or NULL if not needed +# define PASSWORD NULL +//------------------------------------------------------------------------------------ + +#define MQTT_CLIENT_TYPE MQTTSocket +#include "MQTTSocket.h" +// need a wrapper since K64F and LPC1768 wont have the same name for mii read methods +static uint32_t linkStatus(void) { return true; } bool quickstartMode = true; char org[11] = ORG; @@ -298,43 +316,6 @@ return client->publish(pubTopic, message); } - -#if defined(TARGET_K64F) -int getUUID48(char* buf, int buflen) -{ - unsigned int UUID_LOC_WORD0 = 0x40048060; - unsigned int UUID_LOC_WORD1 = 0x4004805C; - - // Fetch word 0 - uint32_t word0 = *(uint32_t *)UUID_LOC_WORD0; - - // Fetch word 1 - // we only want bottom 16 bits of word1 (MAC bits 32-47) - // and bit 9 forced to 1, bit 8 forced to 0 - // Locally administered MAC, reduced conflicts - // http://en.wikipedia.org/wiki/MAC_address - uint32_t word1 = *(uint32_t *)UUID_LOC_WORD1; - word1 |= 0x00000200; - word1 &= 0x0000FEFF; - - int rc = snprintf(buf, buflen, "%4x%08x", word1, word0); // Device id must be in lower case - - return rc; -} -#elif !defined(USE_CELLULAR) -char* getMac(EthernetInterface& eth, char* buf, int buflen) // Obtain MAC address -{ - strncpy(buf, eth.getMACAddress(), buflen); - - char* pos; // Remove colons from mac address - while ((pos = strchr(buf, ':')) != NULL) - memmove(pos, pos + 1, strlen(pos) + 1); - return buf; -} -#else -#endif - - void messageArrived(MQTT::MessageData& md) { MQTT::Message &message = md.message; @@ -384,28 +365,21 @@ Thread yellow_thread(flashing_yellow); #endif -#ifdef USE_CELLULAR MDMSerial mdm; //mdm.setDebug(4); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) return -1; -#endif + MQTT_CLIENT_TYPE ipstack; MQTT::Client<MQTT_CLIENT_TYPE, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack); if (quickstartMode) { -#if defined(TARGET_K64F) - getUUID48(id, sizeof(id)); // getMac doesn't work on the K64F -#elif !defined(USE_CELLULAR) - getMac(ipstack.getEth(), id, sizeof(id)); -#else MDMParser::NetStatus status; if (mdm.checkNetStatus(&status) && *status.num) { int l = strlen(status.num); strcpy(id, "000000000000"); strcpy(id+12-l, status.num); } -#endif } attemptConnect(&client, &ipstack);