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
Revision 13:6a0af5deb2db, committed 2015-03-13
- Comitter:
- mazgch
- Date:
- Fri Mar 13 06:23:30 2015 +0000
- Parent:
- 12:d6b94e8051b0
- Child:
- 14:6f36d75b3917
- Commit message:
- The cellular IBM IoT example is now compatible with any Arduino based board and the cellular & positioning shield.
Changed in this revision
--- a/C027.h Thu Mar 12 12:31:06 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Ian Craggs - initial implementation - *******************************************************************************/ - -#if !defined(C027_H) -#define C027_H - -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 - //------------------------------------------------------------------------------------ -// 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 -static uint32_t linkStatus(void) { return 1; } -#else -#include "lpc_phy.h" -// need a wrapper since K64F and LPC1768 wont have the same name for mii read methods -static uint32_t linkStatus(void) -{ - return (lpc_mii_read_data() & 1); -} - -#endif - -#endif \ No newline at end of file
--- a/C027_Support.lib Thu Mar 12 12:31:06 2015 +0000 +++ b/C027_Support.lib Fri Mar 13 06:23:30 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/ublox/code/C027_Support/#c2c4b6b421c8 +http://mbed.org/teams/ublox/code/C027_Support/#db878a234544
--- a/K64F.h Thu Mar 12 12:31:06 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Ian Craggs - initial implementation - * Sam Grove - added method to check the status of the Ethernet cable - *******************************************************************************/ - -#if !defined(K64F_H) -#define K64F_H - -C12832 lcd(D11, D13, D12, D7, D10); -BusOut led2 (LED_BLUE); -BusOut r (D5); -BusOut g (D9); -BusOut b (D8); -MMA7660 MMA(PTE25, PTE24); -LM75B sensor(PTE25, PTE24); -DigitalIn Up(A2); DigitalIn Down(A3); DigitalIn Right(A4); DigitalIn Left(A5); DigitalIn Click(D4); -AnalogIn ain1(A0); AnalogIn ain2(A1); - -#define LED2_OFF 1 -#define LED2_ON 0 - -#define DEFAULT_TYPE_NAME "iotsample-mbed-k64f" - -//#include "lpc_phy.h" -// need a wrapper since K64F and LPC1768 wont have the same name for mii read methods -static uint32_t linkStatus(void) -{ - return (1); -} - -#endif \ No newline at end of file
--- a/LPC1768.h Thu Mar 12 12:31:06 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Ian Craggs - initial implementation - * Sam Grove - added mehtod to check the status of the Ethernet cable - *******************************************************************************/ - -#if !defined(LPC1768_H) -#define LPC1768_H - -C12832 lcd(p5, p7, p6, p8, p11); -DigitalOut led2(LED2); -PwmOut r(p23); -PwmOut g(p24); -PwmOut b(p25); -MMA7660 MMA(p28, p27); -LM75B sensor(p28, p27); -DigitalIn Down(p12); -DigitalIn Left(p13); -DigitalIn Click(p14); -DigitalIn Up(p15); -DigitalIn Right(p16); -AnalogIn ain1(p19); -AnalogIn ain2(p20); - -#define LED2_OFF 0 -#define LED2_ON 1 - -#define DEFAULT_TYPE_NAME "iotsample-mbed-lpc1768" - -#include "lpc_phy.h" -// need a wrapper since K64F and LPC1768 wont have the same name for mii read methods -static uint32_t linkStatus(void) -{ - return (lpc_mii_read_data() & 1); -} - -#endif \ No newline at end of file
--- 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);