![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Diff: main.cpp
- Revision:
- 28:4650c541b029
- Parent:
- 24:224c07ec3bd0
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) {