Dreamforce 2014 Demo of RFID-based Salesforce Case generation for status reporting.

Dependencies:   ID12RFID ReportDB SalesforceCaseGenerator SalesforceInterface

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers StatusReporter.cpp Source File

StatusReporter.cpp

00001 /* Copyright C2014 ARM, MIT License
00002  *
00003  * Author: Doug Anson (doug.anson@arm.com)
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00006  * and associated documentation files the "Software", to deal in the Software without restriction,
00007  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00008  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in all copies or
00012  * substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00015  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00016  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00017  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00019  */
00020  
00021  #include "StatusReporter.h"
00022  
00023  // Logging
00024  #define LOG_CONSOLE(...) { if (this->logger() != NULL) { this->logger()->logConsole(__VA_ARGS__); } }
00025  
00026  // ****************** DreamForce 2014 ******************// 
00027  
00028  // TEMP SENSOR - The TMP36 sensor uses A3 in the shield.. See Definitions.h for the define.
00029  //
00030  // Uncommnent the following line to bind to the TMP36 temperature sensor
00031  //
00032  // AnalogIn tmp36_temp_sensor(TEMP_PIN);
00033  
00034  // ****************** DreamForce 2014 ******************// 
00035  
00036  StatusReporter::StatusReporter(HTTPClient *http,Logger *logger) : m_case_generator(http,logger), m_db(), m_rfid_reader(RFID_TX_PIN,RFID_RX_PIN) {
00037      this->m_logger = logger;
00038  }
00039  
00040  StatusReporter::~StatusReporter() {
00041  }
00042  
00043  Logger *StatusReporter::logger() { return this->m_logger; }
00044  
00045  // Calculate the ambient temperature of the TMP36 sensor in C...
00046  int StatusReporter::getLocalTemperature() {
00047      // TEMP SENSOR: temperature calculation per TMP36 data sheet
00048      //
00049      // Celcius temperature is calculated as follows (with 3.3V input):
00050      //
00051      //      tempC = ((temperature_sensor_voltage*3.3) - 0.6) * 100.0;
00052      //
00053      // You can use the following code snippet:
00054      // 
00055      //      float tempC = (float)(((float)tmp36_temp_sensor*3.3)-0.600)*100.0;
00056      //
00057      // in place of:
00058      // 
00059      //      float tempC = 0.0;
00060      // 
00061      // to calculate the ambient temperature via the TMP36 sensor (in Celcius)
00062      //
00063      
00064      float tempC = 0.0;
00065      
00066      // DEBUG
00067      LOG_CONSOLE("Ambient Temp: %.1f C",tempC);
00068      
00069      // convert to int for brevity...
00070      return (int)tempC;
00071  }
00072  
00073  void StatusReporter::checkAndReportOnStatus() { 
00074     // look for a readable RFID tag
00075     if(this->m_rfid_reader.readable()) {
00076         // capture the RFID id...
00077         LOG_CONSOLE("RFID: Found RFID.\r\nReading...");
00078         int rfid = this->m_rfid_reader.read();
00079         LOG_CONSOLE("RFID: ID %d found...\r\nProcessing...",rfid);
00080         
00081         // look it up in our ReportDB... proceed only if we find something we know about...
00082         char *name = this->m_db.lookupReportName(rfid);
00083         if (name != NULL) {
00084             // build out a simple subject for the case
00085             char subject[DB_MAX_NAME_LENGTH+1];
00086             memset(subject,0,DB_MAX_NAME_LENGTH+1);
00087             sprintf(subject,"%s case update",name);
00088             
00089             // create and dispatch a case
00090             this->m_logger->turnLEDPurple();
00091             char *description = this->m_db.lookupReportDescription(rfid);
00092             char *condition = this->m_db.lookupReportCondition(rfid);
00093             int temperature = this->getLocalTemperature();
00094             char *latitude = this->m_db.lookupReportLatitude(rfid);
00095             char *longitude = this->m_db.lookupReportLongitude(rfid);
00096             bool success = this->m_case_generator.createAnonymousCase(subject,description,condition,temperature,latitude,longitude);
00097             if (success == true) {
00098                 LOG_CONSOLE("Case Generated!\r\nScanning...");
00099                 this->m_logger->turnLEDGreen();
00100             }
00101             else {
00102                 LOG_CONSOLE("Case Generation FAILED\r\nScanning...");
00103                 this->m_logger->turnLEDYellow();
00104             }
00105         }
00106         else {
00107             // unrecognized RFID
00108             LOG_CONSOLE("RFID %d unknown.\r\nScanning...",rfid);
00109         }
00110      }
00111  }