Data Transfer over Wifi and Serial Interface


#1

So I had my code working perfectly for publishing my sensor data to my cayenne dashboard over wifi but once I tried to set up my serial interface for debugging my data stopped publishing to the dashboard and now only displays in the serial interface with my sensor readings and my subscribed values collected from the dashboard. How can I get the data to show up on both the serial debug window along with the dashboard?


#2

Hard to tell anything without code/hardware setup presented.


#3
// Core library for code-sense - IDE-based
#include "Energia.h"
#include <WiFi.h>
//#include <OPT3001.h>
#include <OPT3001_Revised.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <BMA222.h>
#include "Adafruit_TMP007.h"
#include <CayenneMQTTWiFi.h>
#include <SPI.h>

#define CAYENNE_PRINT Serial
// Define structures and classes
WiFiServer myServer(80); // Port 80
uint8_t oldCountClients = 0;
uint8_t countClients = 0;

//boolean opt;

Adafruit_TMP007 tmp007(0x40);
Adafruit_BME280 bme; //(0x77)
BMA222 bma222;
opt3001 opt3001; //(0x47)

boolean state = false;

//initialize variables to store sensor readings
float temp = 0;
float pressure = 0;
float finalpressure = 0;
float humidity = 0;
float diet = 0;       //Ambient temperature sensor in degrees Celsius
float lux = 0;     //variable to store output from light sensor in Lux
float objt = 0;
float timePast = 0; //variable to store the number of milliseconds since the Microcontroller was powered up
float occ = 0;

//initialize variables to store device settings
int lights1 = 0;
int occupancy1 = 0;
int temp1 = 0;
int fan = 0;
int shade = 0;

const uint32_t period_ms = 10000;
uint32_t chrono = 0;

void setup()
{
//  Wire.begin();

  opt3001.begin();  //This function makes a call to initialize the OPT3001


  if (! tmp007.begin()) {   //Initializes the TMP007 and returns an error which halts the program if the initialization failed
    Serial.println("Could not find a valid TMP007 sensor.");
    while (1);
  }
  if (! bme.begin()) {      //Initializes the BME280 and returns an error which halts the program if the initialization failed
    Serial.println("Could not find a valid BME280 sensor.");
    while (1);
  }

  opt3001.begin();

  Cayenne.begin(username, password, clientID, wifi_name, wifi_password);  
  Serial.begin(9600);
  Serial.println("Connected to Cayenne and CC3200"); 
  
}

// Add loop code
void loop()
{
  
  Cayenne.loop();
//tell to start writing
  Cayenne.virtualWrite(0, chrono);
  
// Publish data every (period_ms) ms  
if (millis() > chrono)
    {
        chrono = millis() + period_ms;


      temp = bme.readTemperature();    //Returns temperature in Celsius

     lux = opt3001.readResult();


      pressure = bme.readPressure();       //Returns pressure in pascals (Pa)
      finalpressure = pressure / 100;      //returns hPa


      humidity = bme.readHumidity();       //Returns Humidity in percentage


      // This is the tempurature reading for what is in front of the sensor
      objt = tmp007.readObjTempC();     //Stores output from Object temperature sensor in degrees Celsius;

      delay(1000);                            //This is used to delay time between taking sensor readings

//// Write to the Cayenne dashboard
//      Cayenne.luxWrite(1, lux);
//      Cayenne.hectoPascalWrite(2, finalpressure);
//      Cayenne.virtualWrite(4, humidity);
//      Cayenne.celsiusWrite(5,objt);
////      Cayenne.celsiusWrite(3, temp);

      Cayenne.virtualWrite(1, lux);
      Cayenne.virtualWrite(2, finalpressure);      
      Cayenne.virtualWrite(4, humidity);
      Cayenne.virtualWrite(5, objt);
            
//print sensors readings
      Serial.print(lux); 
      Serial.print(" Lux ");
      Serial.print(finalpressure); 
      Serial.print(" hPa ");
      Serial.print(humidity); 
      Serial.print(" % Humidity ");
      Serial.print(objt); 
      Serial.println(" Temp ");
                        
//print the device settings to serial port
      Serial.print(fan); 
      Serial.print(" Fan ");
      Serial.print(shade); 
      Serial.print(" Shade ");
      Serial.print(occupancy1); 
      Serial.print(" Ppl in Room ");
      Serial.print(lights1); 
      Serial.print(" % of lights ");
      Serial.print(temp1); 
      Serial.println(" Temp Setting ");

      Serial.println(" ");
      delay(100);

  }

}

CAYENNE_IN(6) {
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  fan = getValue.asInt();

}  

CAYENNE_IN(7) {
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  shade = getValue.asInt();

}  

CAYENNE_IN(8) {
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  occupancy1 = getValue.asInt();

}  

CAYENNE_IN(9) {
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  lights1 = getValue.asInt();

}  

CAYENNE_IN(10) {
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  temp1 = getValue.asInt();

}

#4

excluded the wifi and cayenne set up


#5

add this line.

#define CAYENNE_DEBUG