DIYmall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module
Dependencies: Adafruit_GFX SDFileSystem
Fork of ATT_AWS_IoT_demo by
Revision 28:4650c541b029, committed 2018-10-09
- Comitter:
- afmiee
- Date:
- Tue Oct 09 20:57:34 2018 +0000
- Parent:
- 27:2f486c766854
- Commit message:
- DIYmall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module
Changed in this revision
diff -r 2f486c766854 -r 4650c541b029 AWS_openssl/aws_iot_config.h --- a/AWS_openssl/aws_iot_config.h Tue Feb 07 16:18:57 2017 +0000 +++ b/AWS_openssl/aws_iot_config.h Tue Oct 09 20:57:34 2018 +0000 @@ -33,13 +33,13 @@ // ================================================= // USER ENTERED VALUES (only used when not using SD card) -#define AWS_IOT_MQTT_HOST "TODO" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow +#define AWS_IOT_MQTT_HOST "avy9htt9ufbgq.iot.us-east-1.amazonaws.com" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow #define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S -#define AWS_IOT_MQTT_CLIENT_ID "TODO" ///< MQTT client ID should be unique for every device -#define AWS_IOT_MY_THING_NAME "TODO" ///< Thing Name of the Shadow this device is associated with -#define AWS_IOT_MY_TOPIC "TODO/%s" ///< Topic name to publish to (used with alternate demo) +#define AWS_IOT_MQTT_CLIENT_ID "test" ///< MQTT client ID should be unique for every device +#define AWS_IOT_MY_THING_NAME "test" ///< Thing Name of the Shadow this device is associated with +#define AWS_IOT_MY_TOPIC "test/%s" ///< Topic name to publish to (used with alternate demo) -//#ifdef USING_SD_CARD // These files are only valid when SD card is being used +#ifdef USING_SD_CARD // These files are only valid when SD card is being used // Example format for mqtt_config.txt: /* AWS_IOT_MQTT_HOST=1234asdf.iot.us-west-2.amazonaws.com @@ -51,12 +51,12 @@ #define AWS_IOT_ROOT_CA_FILENAME "/sd/certs/rootCA-certificate.crt" ///< Root CA file name #define AWS_IOT_CERTIFICATE_FILENAME "/sd/certs/certificate.pem.crt" ///< device signed certificate file name #define AWS_IOT_PRIVATE_KEY_FILENAME "/sd/certs/private.pem.key" ///< Device private key filename -//#endif +#endif // ================================================= // MQTT PubSub -#define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow -#define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. +#define AWS_IOT_MQTT_TX_BUF_LEN 2048 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow +#define AWS_IOT_MQTT_RX_BUF_LEN 2048 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow // Thing Shadow specific configs
diff -r 2f486c766854 -r 4650c541b029 AWS_openssl/aws_iot_src/utils/aws_iot_log.h --- a/AWS_openssl/aws_iot_src/utils/aws_iot_log.h Tue Feb 07 16:18:57 2017 +0000 +++ b/AWS_openssl/aws_iot_src/utils/aws_iot_log.h Tue Oct 09 20:57:34 2018 +0000 @@ -27,7 +27,7 @@ // Change to a number between 1 and 4 to debug the TLS connection // WARNING: the large number of prints may cause timeouts during the connection. -#define DEBUG_LEVEL 0 +#define DEBUG_LEVEL 1 #ifndef _IOT_LOG_H #define _IOT_LOG_H
diff -r 2f486c766854 -r 4650c541b029 Adafruit_GFX.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_GFX.lib Tue Oct 09 20:57:34 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/afmiee/code/Adafruit_GFX/#5ae7e46da43f
diff -r 2f486c766854 -r 4650c541b029 README.md --- a/README.md Tue Feb 07 16:18:57 2017 +0000 +++ b/README.md Tue Oct 09 20:57:34 2018 +0000 @@ -138,7 +138,7 @@ //return outOfBoxDemo(); 3) In the mbed ATT_AWS_IoT_demo project open "aws_iot_config.h" and set the AWS_IOT_MY_TOPIC: - #define AWS_IOT_MY_TOPIC "ExampleTopic/%s" + #define "ExampleTopic/%s" 4) In AWS Console go to AWS IoT -> Test -> Subscribe to a topic and as the topic name put in "ExampleTopic/+" // NOTE: the "/+" is a wildcard, this demo puts the ICCID there. This allows you to have multiple devices
diff -r 2f486c766854 -r 4650c541b029 WNCInterface/WNCInterface.h --- a/WNCInterface/WNCInterface.h Tue Feb 07 16:18:57 2017 +0000 +++ b/WNCInterface/WNCInterface.h Tue Oct 09 20:57:34 2018 +0000 @@ -31,7 +31,7 @@ #ifndef _WNCINTERFACE_H_ #define _WNCINTERFACE_H_ -#define WNC_DEBUG 0 //1=enable the WNC startup debug output +#define WNC_DEBUG 1 //1=enable the WNC startup debug output //0=disable the WNC startup debug output #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs //0=simply return failed response for all socket calls @@ -96,7 +96,6 @@ class WNCInterface { - class WncControllerK64F; //forward reference the Controller Class friend class TCPSocketConnection; friend class UDPSocket; friend class Endpoint; @@ -104,6 +103,7 @@ friend class WNCSms; public: + class WncControllerK64F; //forward reference the Controller Class /** Create WNC Data Module Interface Instance for the device (M14A2A) */ WNCInterface(); @@ -155,7 +155,7 @@ //private: static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics - static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance + static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the instance static string mac; };
diff -r 2f486c766854 -r 4650c541b029 WNCInterface/WncControllerK64F/WncController/WncController.cpp --- a/WNCInterface/WncControllerK64F/WncController/WncController.cpp Tue Feb 07 16:18:57 2017 +0000 +++ b/WNCInterface/WncControllerK64F/WncController/WncController.cpp Tue Oct 09 20:57:34 2018 +0000 @@ -31,6 +31,9 @@ #include <cctype> #include "WncController.h" +extern int16_t RSSI; + + namespace WncController_fk { ///////////////////////////////////////////////////// @@ -2008,8 +2011,10 @@ return (false); } + bool WncController::at_getrssiber_wnc(int16_t * dBm, int16_t * ber) { + string * pRespStr; AtCmdErr_e cmdRes; cmdRes = at_send_wnc_cmd("AT+CSQ", &pRespStr, m_sCmdTimeoutMs); // Check RSSI,BER @@ -2047,6 +2052,7 @@ else { dbgPuts("Invalid RSSI!"); return (false); + RSSI = *dBm; } // Parse out BER: 0..7 as RXQUAL values in the table 3GPP TS 45.008 subclause 8.2.4 // 99 - unknown or undetectable @@ -2078,7 +2084,37 @@ dbgPuts("<-------- Begin Cell Status ------------"); cmdRes1 = at_send_wnc_cmd("AT+CSQ", &pRespStr, m_sCmdTimeoutMs); // Check RSSI,BER - + if (pRespStr->size() == 0) + { + dbgPuts("Strange RSSI result!"); + return (false); + } + else + { + size_t pos1 = pRespStr->find("SQ:"); + size_t pos2 = pRespStr->rfind(","); + // Sanity check + if ((pos1 != string::npos) && (pos2 != string::npos) && (pos2 > pos1)) + { + string subStr = pRespStr->substr(pos1 + 4, pos2 - pos1 ); + int rawRssi = atoi(subStr.c_str()); + if (rawRssi == 99) + RSSI = -199; + else if (rawRssi == 0) + RSSI = -113; + else if (rawRssi == 1) + RSSI = -111; + else if (rawRssi == 31) + RSSI = -51; + else if (rawRssi >= 2 && rawRssi <= 30) + RSSI = -113 + 2 * rawRssi; + else + { + dbgPuts("Invalid RSSI!"); + return (false); + } + } + } // If no response, don't bother with more commands if (cmdRes1 != WNC_AT_CMD_TIMEOUT) cmdRes2 = at_send_wnc_cmd("AT+CPIN?", &pRespStr, m_sCmdTimeoutMs); // Check if SIM locked
diff -r 2f486c766854 -r 4650c541b029 main.cpp --- a/main.cpp Tue Feb 07 16:18:57 2017 +0000 +++ b/main.cpp Tue Oct 09 20:57:34 2018 +0000 @@ -11,6 +11,7 @@ // Network includes #include "WNCInterface.h" +//#include "./WNCInterface/WncControllerK64F/WncController/WncController.h" #include "network_interface.h" // AWS includes @@ -28,6 +29,9 @@ #include "mbedtls/debug.h" #endif +#include "Adafruit_SSD1306.h" + + //===================================================================================================================== // // Defines @@ -103,6 +107,9 @@ // Temp/humidity object HTS221 hts221; + +unsigned int Counter = 0; // Packet counter +int16_t RSSI = 0; //===================================================================================================================== // // Devices @@ -122,6 +129,21 @@ // I2C bus (SDA, SCL) I2C i2c(PTC11, PTC10); +class I2CPreInit : public I2C +{ +public: + I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) + { +// frequency(100000); +// start(); + }; +}; + + +// OLED +I2CPreInit gI2C(D14,D15); +Adafruit_SSD1306_I2c gOled2(gI2C,D4); + //===================================================================================================================== // // Functions @@ -194,6 +216,11 @@ INFO("LED: White"); break; } + INFO("RSSI = %d\n\r",RSSI); + gOled2.setTextCursor(0,32); + gOled2.printf("PKT#: %6d\n",Counter); + gOled2.printf("RSSI: %6d dBms\n",RSSI); + gOled2.display(); } //===================================================================================================================== @@ -288,18 +315,35 @@ // the demo S3 website pulls that data from the DynamoDB and displays it. // //===================================================================================================================== -int outOfBoxDemo() { +const char PayLoad[] = "0123456789ABCDEF"; +//char PayLoad1056[1057]; +#define PACKETS16B 66 +#define PACKET 16 +char cPayload[PACKET*PACKETS16B+1]; + + + +int outOfBoxDemo(void) { INFO("Running Out-of-Box Function (alternate demo)."); IoT_Error_t rc = NONE_ERROR; int32_t i = 0; int publishCount = 0; bool infinitePublishFlag = true; - char cPayload[100]; + //char cPayload[PACKET*PACKETS16B+1]; char cTopic[100]; const string colorStrings[] = {"Off", "Red", "Green", "", "Blue", "", "", "White"}; float updateInterval = 1.0; // seconds + int j,k; + char CntStrng[17]; + + + for(j = 0; j < PACKETS16B; j++) + for(k = 0; k < PACKET; k++) + cPayload[PACKET*j + k] = PayLoad[k]; + cPayload[16*PACKETS16B ] = 0x00; + MQTTConnectParams connectParams = MQTTConnectParamsDefault; connectParams.KeepAliveInterval_sec = 10; connectParams.isCleansession = true; @@ -378,6 +422,7 @@ // Whenever the software button (SW3) is pressed the LED will changes color and this will // trigger a publish to the AWS topic specified. + buttonOverride = true; if (buttonOverride) { buttonOverride = false; @@ -386,7 +431,12 @@ humidity = hts221.readHumidity(); // Loading data into JSON format - sprintf(cPayload, "{\"color\":\"%s\",\"temperature\":%f,\"humidity\":%d}", colorStrings[ledColor], temperature, humidity); + //sprintf(cPayload, "{\"color\":\"%s\",\"temperature\":%f,\"humidity\":%d}", colorStrings[ledColor], temperature, humidity); + //sprintf(cPayload, PayLoad1056 ); + sprintf(CntStrng, "%08d%08d", abs(RSSI), ++Counter ); + printf("%s\n\r", CntStrng); + for( k = 0; k < PACKET; k++ ) + cPayload[k] = CntStrng[k]; Msg.PayloadLen = strlen(cPayload) + 1; Params.MessageParams = Msg; @@ -414,17 +464,24 @@ return rc; } + //===================================================================================================================== // // Main // //===================================================================================================================== + int main() { // Set baud rate for PC Serial pc.baud(115200); INFO("Hello World from AT&T IoT Start Kit demo!"); - + gOled2.clearDisplay(); + gOled2.display(); + wait(0.5); + gOled2.printf("Latch Cellular EVM\r\n"); + gOled2.display(); + int i; IoT_Error_t rc = NONE_ERROR; char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER]; @@ -494,7 +551,7 @@ // NOTE: You can comment in the following line for an alternate demo that // is used as the out-of-box demo binary that comes with the AT&T IoT // Starter Kit. It loops instead of the rest of Main() - //return outOfBoxDemo(); + // return outOfBoxDemo(); //========================================================================== // Intialize MQTT/Cert parameters @@ -522,7 +579,7 @@ INFO("Initialize the MQTT client..."); MQTTClient_t mqttClient; aws_iot_mqtt_init(&mqttClient); - + return outOfBoxDemo(); INFO("Shadow Init..."); rc = aws_iot_shadow_init(&mqttClient); if (NONE_ERROR != rc) {