Ardino UNO Sketch too long


Try this. Only 70% resources used:

Cayenne Ethernet Example

This sketch connects to the Cayenne server using an Arduino Ethernet Shield W5100
and runs the main communication loop.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

1. Set the token variable to match the Arduino token from the Dashboard.
2. Compile and upload this sketch.

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneEthernet.h>

#include "EmonLib.h"                   // Include Emon Library

EnergyMonitor emon1;

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "YOUR TOKEN";

unsigned long lastMillis = 0;

void setup()

  //load calibration factors into energy monitor
  emon1.voltage(2, 234, 1.7); // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 19.9); // Current: input pin, calibration. 

void loop()

  //Take a power measurment every six seconds
  if (millis() - lastMillis > 6000) {

    lastMillis = millis();

    emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out

   //update dashboard with last real power
   Cayenne.virtualWrite(1, emon1.realPower);

   //update dashboard with last apparent power
   Cayenne.virtualWrite(2, emon1.apparentPower);

   //update dashboard with last AC voltage
   Cayenne.virtualWrite(3, emon1.Vrms);

   //update dashboard with last AC current
   Cayenne.virtualWrite(4, emon1.Irms);

   //update dashboard with last power factor
   Cayenne.virtualWrite(5, emon1.powerFactor);