Demo application for using the AT&T IoT Starter Kit Powered by AWS.

Dependencies:   SDFileSystem

Fork of ATT_AWS_IoT_demo by Anthony Phillips

IoT Starter Kit Powered by AWS Demo

This program demonstrates the AT&T IoT Starter Kit sending data directly into AWS IoT. It's explained and used in the Getting Started with the IoT Starter Kit Powered by AWS on starterkit.att.com.

What's required

  • AT&T IoT LTE Add-on (also known as the Cellular Shield)
  • NXP K64F - for programming
  • microSD card - used to store your AWS security credentials
  • AWS account
  • Python, locally installed

If you don't already have an IoT Starter Kit, you can purchase a kit here. The IoT Starter Kit Powered by AWS includes the LTE cellular shield, K64F, and a microSD card.

Committer:
ampembeng
Date:
Thu Dec 15 18:05:09 2016 +0000
Revision:
23:b9ff83dc965f
Parent:
15:6f2798e45099
Added an alternate demo that publishes JSON data to a topic instead of using the device shadow.  The topic (rule) is intended to be used along with DynamoDB and S3 (a static website).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ampembeng 15:6f2798e45099 1 /* =====================================================================
ampembeng 15:6f2798e45099 2 Copyright © 2016, Avnet (R)
ampembeng 15:6f2798e45099 3
ampembeng 15:6f2798e45099 4 Contributors:
ampembeng 15:6f2798e45099 5 * James Flynn, www.em.avnet.com
ampembeng 15:6f2798e45099 6
ampembeng 15:6f2798e45099 7 Licensed under the Apache License, Version 2.0 (the "License");
ampembeng 15:6f2798e45099 8 you may not use this file except in compliance with the License.
ampembeng 15:6f2798e45099 9 You may obtain a copy of the License at
ampembeng 15:6f2798e45099 10
ampembeng 15:6f2798e45099 11 http://www.apache.org/licenses/LICENSE-2.0
ampembeng 15:6f2798e45099 12
ampembeng 15:6f2798e45099 13 Unless required by applicable law or agreed to in writing,
ampembeng 15:6f2798e45099 14 software distributed under the License is distributed on an
ampembeng 15:6f2798e45099 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
ampembeng 15:6f2798e45099 16 either express or implied. See the License for the specific
ampembeng 15:6f2798e45099 17 language governing permissions and limitations under the License.
ampembeng 15:6f2798e45099 18
ampembeng 15:6f2798e45099 19 @file WNCInterface.h
ampembeng 15:6f2798e45099 20 @version 1.0
ampembeng 15:6f2798e45099 21 @date Sept 2016
ampembeng 15:6f2798e45099 22
ampembeng 15:6f2798e45099 23 ======================================================================== */
ampembeng 15:6f2798e45099 24
ampembeng 15:6f2798e45099 25
ampembeng 15:6f2798e45099 26 #include <stddef.h>
ampembeng 15:6f2798e45099 27 #include "WncControllerK64F/WncControllerK64F.h"
ampembeng 15:6f2798e45099 28 #include "WncControllerK64F/WncController/WncController.h"
ampembeng 15:6f2798e45099 29 #include <Mutex.h>
ampembeng 15:6f2798e45099 30
ampembeng 15:6f2798e45099 31 #ifndef _WNCINTERFACE_H_
ampembeng 15:6f2798e45099 32 #define _WNCINTERFACE_H_
ampembeng 15:6f2798e45099 33
ampembeng 15:6f2798e45099 34 #define WNC_DEBUG 0 //1=enable the WNC startup debug output
ampembeng 15:6f2798e45099 35 //0=disable the WNC startup debug output
ampembeng 15:6f2798e45099 36 #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs
ampembeng 15:6f2798e45099 37 //0=simply return failed response for all socket calls
ampembeng 15:6f2798e45099 38 #define DISPLAY_FE 1 //1 to display the fatal error when it occurs
ampembeng 15:6f2798e45099 39 //0 to NOT display the fatal error
ampembeng 15:6f2798e45099 40 #define RESETON_FE 0 //1 to cause the MCU to reset on fatal error
ampembeng 15:6f2798e45099 41 //0 to NOT reset the MCU
ampembeng 15:6f2798e45099 42 #define APN_DEFAULT "m2m.com.attz"
ampembeng 15:6f2798e45099 43
ampembeng 15:6f2798e45099 44 //
ampembeng 15:6f2798e45099 45 // WNC Error Handling macros & data
ampembeng 15:6f2798e45099 46 //
ampembeng 15:6f2798e45099 47 #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE
ampembeng 15:6f2798e45099 48 #define WNC_GOOD WncController_fk::WncController::WNC_ON
ampembeng 15:6f2798e45099 49
ampembeng 15:6f2798e45099 50 #define RETfail return -1
ampembeng 15:6f2798e45099 51 #define RETvoid return
ampembeng 15:6f2798e45099 52 #define RETnull return NULL
ampembeng 15:6f2798e45099 53 #define RETresume
ampembeng 15:6f2798e45099 54
ampembeng 15:6f2798e45099 55 #define DORET(x) RET##x
ampembeng 15:6f2798e45099 56
ampembeng 15:6f2798e45099 57 #define TOSTR(x) #x
ampembeng 15:6f2798e45099 58 #define INTSTR(x) TOSTR(x)
ampembeng 15:6f2798e45099 59 #define FATAL_STR __FILE__ ":" INTSTR(__LINE__)
ampembeng 15:6f2798e45099 60
ampembeng 15:6f2798e45099 61
ampembeng 15:6f2798e45099 62 #if RESETON_FE == 1
ampembeng 15:6f2798e45099 63 #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L))
ampembeng 15:6f2798e45099 64 #define RSTMSG "RESET MCU! "
ampembeng 15:6f2798e45099 65 #else
ampembeng 15:6f2798e45099 66 #define MCURESET
ampembeng 15:6f2798e45099 67 #define RSTMSG ""
ampembeng 15:6f2798e45099 68 #endif
ampembeng 15:6f2798e45099 69
ampembeng 15:6f2798e45099 70 #if DISPLAY_FE == 1
ampembeng 15:6f2798e45099 71 #define PFE {extern MODSERIAL *_dbgout;if(_dbgout)_dbgout->printf(RSTMSG "\r\n>>WNC FAILED @ %s\r\n", FATAL_STR);}
ampembeng 15:6f2798e45099 72 #else
ampembeng 15:6f2798e45099 73 #define PFE
ampembeng 15:6f2798e45099 74 #endif
ampembeng 15:6f2798e45099 75
ampembeng 15:6f2798e45099 76 #if STOP_ON_FE == 1
ampembeng 15:6f2798e45099 77 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);}
ampembeng 15:6f2798e45099 78 #else
ampembeng 15:6f2798e45099 79 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);}
ampembeng 15:6f2798e45099 80 #endif
ampembeng 15:6f2798e45099 81
ampembeng 15:6f2798e45099 82 #define M_LOCK {extern Mutex _WNCLock; _WNCLock.lock();}
ampembeng 15:6f2798e45099 83 #define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();}
ampembeng 15:6f2798e45099 84 #define CHK_WNCFE(x,y) if( x ){M_ULOCK; FATAL_WNC_ERROR(y);}
ampembeng 15:6f2798e45099 85
ampembeng 15:6f2798e45099 86 // Because the WncController has intermixed socket & interface functionallity
ampembeng 15:6f2798e45099 87 // will need to make the Socket class a friend of the Interface class. This
ampembeng 15:6f2798e45099 88 // will allow the Socket class to get to the WNC functions needed for the
ampembeng 15:6f2798e45099 89 // socket. Forward reference the class
ampembeng 15:6f2798e45099 90
ampembeng 15:6f2798e45099 91 class Socket;
ampembeng 15:6f2798e45099 92 class Endpoint;
ampembeng 15:6f2798e45099 93 class UDPSocket;
ampembeng 15:6f2798e45099 94 class TCPSocketConnection;
ampembeng 15:6f2798e45099 95 class WNCSms;
ampembeng 15:6f2798e45099 96
ampembeng 15:6f2798e45099 97 class WNCInterface
ampembeng 15:6f2798e45099 98 {
ampembeng 15:6f2798e45099 99 class WncControllerK64F; //forward reference the Controller Class
ampembeng 15:6f2798e45099 100 friend class TCPSocketConnection;
ampembeng 15:6f2798e45099 101 friend class UDPSocket;
ampembeng 15:6f2798e45099 102 friend class Endpoint;
ampembeng 15:6f2798e45099 103 friend class Socket;
ampembeng 15:6f2798e45099 104 friend class WNCSms;
ampembeng 15:6f2798e45099 105
ampembeng 15:6f2798e45099 106 public:
ampembeng 15:6f2798e45099 107 /** Create WNC Data Module Interface Instance for the device (M14A2A) */
ampembeng 15:6f2798e45099 108 WNCInterface();
ampembeng 15:6f2798e45099 109
ampembeng 15:6f2798e45099 110 /** Initialize the interface (no connection at this point).
ampembeng 15:6f2798e45099 111 * \return 0 on success, a negative number on failure
ampembeng 15:6f2798e45099 112 */
ampembeng 15:6f2798e45099 113 static int init(const char* apn=NULL, MODSERIAL * debug=NULL);
ampembeng 15:6f2798e45099 114
ampembeng 15:6f2798e45099 115 /** Open an LTE internet data connection
ampembeng 15:6f2798e45099 116 @return 0 on success, error code on failure
ampembeng 15:6f2798e45099 117 */
ampembeng 15:6f2798e45099 118 int connect(void);
ampembeng 15:6f2798e45099 119
ampembeng 15:6f2798e45099 120 /** Disconnect
ampembeng 15:6f2798e45099 121 * Bring the interface down
ampembeng 15:6f2798e45099 122 * \return 0 on success, a negative number on failure
ampembeng 15:6f2798e45099 123 */
ampembeng 15:6f2798e45099 124 static int disconnect();
ampembeng 15:6f2798e45099 125
ampembeng 15:6f2798e45099 126 /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function
ampembeng 15:6f2798e45099 127 * returns a bogus MAC address created from the ICCD on the SIM that is being used.
ampembeng 15:6f2798e45099 128 * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN"
ampembeng 15:6f2798e45099 129 */
ampembeng 15:6f2798e45099 130 static char* getMACAddress();
ampembeng 15:6f2798e45099 131
ampembeng 15:6f2798e45099 132 /** Get the IP address of your Ethernet interface
ampembeng 15:6f2798e45099 133 * \return a pointer to a string containing the IP address
ampembeng 15:6f2798e45099 134 */
ampembeng 15:6f2798e45099 135 static char* getIPAddress();
ampembeng 15:6f2798e45099 136
ampembeng 15:6f2798e45099 137 /** Get the Gateway address of your Ethernet interface
ampembeng 15:6f2798e45099 138 * \return a pointer to a string containing the Gateway address
ampembeng 15:6f2798e45099 139 */
ampembeng 15:6f2798e45099 140 static char* getGateway();
ampembeng 15:6f2798e45099 141
ampembeng 15:6f2798e45099 142 /** Get the Network mask of your Ethernet interface
ampembeng 15:6f2798e45099 143 * \return a pointer to a string containing the Network mask
ampembeng 15:6f2798e45099 144 */
ampembeng 15:6f2798e45099 145 static char* getNetworkMask();
ampembeng 15:6f2798e45099 146
ampembeng 15:6f2798e45099 147 /** Manipulate the debug output of the WncController, for debug purposes.
ampembeng 15:6f2798e45099 148 * \return nothing.
ampembeng 15:6f2798e45099 149 */
ampembeng 15:6f2798e45099 150 void doDebug(int val); //doing this so I can get to the wnc controller pointer
ampembeng 15:6f2798e45099 151
ampembeng 23:b9ff83dc965f 152 /** Returns full ICCD on the SIM that is being used.
ampembeng 23:b9ff83dc965f 153 */
ampembeng 23:b9ff83dc965f 154 void WNCInterface::getICCID(string *str);
ampembeng 15:6f2798e45099 155
ampembeng 15:6f2798e45099 156 //private:
ampembeng 15:6f2798e45099 157 static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics
ampembeng 15:6f2798e45099 158 static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance
ampembeng 15:6f2798e45099 159 static string mac;
ampembeng 15:6f2798e45099 160
ampembeng 15:6f2798e45099 161 };
ampembeng 15:6f2798e45099 162
ampembeng 15:6f2798e45099 163 #endif /* _WNCINTERFACE_ */
ampembeng 15:6f2798e45099 164
ampembeng 15:6f2798e45099 165