Dependencies: C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed
Fork of IoTClientEthernet by
Revision 20:0bac4068e9c0, committed 2017-01-13
- Comitter:
- datboimina
- Date:
- Fri Jan 13 12:07:54 2017 +0000
- Parent:
- 19:31b65908c2f3
- Commit message:
- Hey
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 31b65908c2f3 -r 0bac4068e9c0 main.cpp --- a/main.cpp Sun Dec 04 14:50:51 2016 +0000 +++ b/main.cpp Fri Jan 13 12:07:54 2017 +0000 @@ -1,27 +1,4 @@ -/******************************************************************************* - * Copyright (c) 2014, 2015 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: - * Sam Danbury - initial implementation - * Ian Craggs - refactoring to remove STL and other changes - * Sam Grove - added check for Ethernet cable. - * Chris Styles - Added additional menu screen for software revision - * James Sutton - Mac fix and extra debug - * Ian Craggs - add not authorized messages - * - * To do : - * Add magnetometer sensor output to IoT data stream - * - *******************************************************************************/ + #include "LM75B.h" #include "MMA7660.h" @@ -30,6 +7,7 @@ #include "C12832.h" #include "Arial12x12.h" #include "rtos.h" +Serial pc(USBTX, USBRX); // Update this to the next number *before* a commit #define __APP_SW_REVISION__ "18" @@ -53,7 +31,7 @@ #warning "Compiling for mbed LPC1768" #include "LPC1768.h" #elif defined(TARGET_K64F) -#warning "Compiling for mbed K64F" + #include "K64F.h" #endif @@ -162,71 +140,30 @@ switch (menuItem) { case 0: - sprintf(line1, "IBM IoT Cloud"); + sprintf(line1, "Food Temp IoT Cloud"); sprintf(line2, "Scroll with joystick"); break; case 1: + sprintf(line1, "Food Storage Temp:"); + sprintf(line2, "%0.4f", sensor.temp()); + break; + case 2: + sprintf(line1, "IP Address:"); + sprintf(line2, "%s", ip_addr); + break; + case 3: + sprintf(line1, "Gateway:"); + sprintf(line2, "%s", gateway_addr); + break; + case 4: sprintf(line1, "Go to:"); sprintf(line2, "http://ibm.biz/iotqstart"); break; - case 2: + case 5: sprintf(line1, "Device Identity:"); sprintf(line2, "%s", id); break; - case 3: - sprintf(line1, "MQTT Status:"); - if (mqttConnecting) - sprintf(line2, "Connecting... %d/5", retryAttempt); - else - { - if (connected) - sprintf(line2, "Connected"); - else - { - switch (connack_rc) - { - case MQTT_CLIENTID_REJECTED: - sprintf(line2, "Clientid rejected"); - break; - case MQTT_BAD_USERNAME_OR_PASSWORD: - sprintf(line2, "Invalid username or password"); - break; - case MQTT_NOT_AUTHORIZED: - sprintf(line2, "Not authorized"); - break; - default: - sprintf(line2, "Disconnected"); - } - } - } - break; - case 4: - sprintf(line1, "Ethernet State:"); - sprintf(line2, ethernetInitialising ? "Initializing..." : "Initialized"); - break; - case 5: - sprintf(line1, "Socket State:"); - if (netConnecting) - sprintf(line2, "Connecting... %d/5", retryAttempt); - else - sprintf(line2, netConnected ? "Connected" : "Disconnected"); - break; - case 6: - sprintf(line1, "IP Address:"); - sprintf(line2, "%s", ip_addr); - break; - case 7: - sprintf(line1, "Gateway:"); - sprintf(line2, "%s", gateway_addr); - break; - case 8: - sprintf(line1, "App version:"); - sprintf(line2, "%s", __APP_SW_REVISION__); - break; - case 9: - sprintf(line1, "Current Timeout:"); - sprintf(line2, "%d ms", connectTimeout); - break; + } if (strcmp(line1, last_line1) != 0 || strcmp(line2, last_line2) != 0) @@ -249,7 +186,7 @@ if (Down) { joystickPos = "DOWN"; - if (menuItem >= 0 && menuItem < 9) + if (menuItem >= 0 && menuItem < 5) printMenu(++menuItem); } else if (Left) @@ -259,7 +196,7 @@ else if (Up) { joystickPos = "UP"; - if (menuItem <= 9 && menuItem > 0) + if (menuItem <= 5 && menuItem > 0) printMenu(--menuItem); } else if (Right) @@ -274,7 +211,7 @@ while(true) { setMenu(); - if (++count % 10 == 0) + if (++count % 6 == 0) printMenu(menuItem); Thread::wait(100); } @@ -288,7 +225,7 @@ { lcd.cls(); lcd.locate(0,0); - lcd.printf("IBM IoT Cloud"); + lcd.printf("Food Temp IoT Cloud"); lcd.locate(0,16); lcd.printf(message); } @@ -345,7 +282,7 @@ { connected = true; green(); - displayMessage("Connected"); + displayMessage("Food Temp IoT Connected"); wait(1); displayMessage("Scroll with joystick"); } @@ -405,8 +342,10 @@ char buf[250]; sprintf(buf, - "{\"d\":{\"myName\":\"IoT mbed\",\"accelX\":%0.4f,\"accelY\":%0.4f,\"accelZ\":%0.4f,\"temp\":%0.4f,\"joystick\":\"%s\",\"potentiometer1\":%0.4f,\"potentiometer2\":%0.4f}}", - MMA.x(), MMA.y(), MMA.z(), sensor.temp(), joystickPos, ain1.read(), ain2.read()); + "{\"d\":{\"Food Storage Fridge Temp IoT\":\"IoT mbed\",\"joystick\":\"%s\",\"temp\":%0.4f}}", + joystickPos, sensor.temp()); + pc.printf("Food Storage Fridge Temp IoT\":\"Temp\":%0.4f", + sensor.temp()); message.qos = MQTT::QOS0; message.retained = false; message.dup = false; @@ -475,7 +414,7 @@ Thread yellow_thread(flashing_yellow); Thread menu_thread(menu_loop); - LOG("***** IBM IoT Client Ethernet Example *****\n"); + LOG("***** Food Temp IoT Cloud Client Ethernet Example *****\n"); MQTTEthernet ipstack; ethernetInitialising = false; MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack); @@ -509,6 +448,8 @@ if (publish(&client, &ipstack) != 0) attemptConnect(&client, &ipstack); // if we have lost the connection count = 0; + + } if (blink_interval == 0)