Tadeas Dvoracek
Published © GPL3+

Old UPS with WiFi Connection

Monitoring and controlling my UPS from Cayenne with SparkFun ESP8266 Thing Dev Board.

AdvancedFull instructions provided6 hours7,193
Old UPS with WiFi Connection

Things used in this project

Hardware components

APC Back-UPS CS 500
×1
SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
22µF/50V
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
LED (generic)
LED (generic)
×4
BC557
×1
BC547
×1
15k ohm resistor
×8
150 ohm resistor
×6
Resistor 1k ohm
Resistor 1k ohm
×1
SHARP PC817
×6
WiFi antenna
×1
Toggle Switch
×1
Step Down Power Supply
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Schematics

UPS-Schematics

Schematics my curcuit

Code

Code

Arduino
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "password";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "username";
char password[] = "password";
char clientID[] = "clientID";

unsigned long lastMillis = 0;

int inputvoltage=LOW;
int line=LOW;
int battery=LOW;

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(5, INPUT);   //ON LINE input
  pinMode(4, INPUT);   //ON BATTERY input
  pinMode(13, INPUT);  //OVER LOAD input
  pinMode(12, INPUT);  //REPLACE BATTERY input
  pinMode(14, OUTPUT); //BUTTON control output
  pinMode(16, INPUT);  //INPUT MAINS VOLTAGE input
}

void loop() {
	Cayenne.loop();

	//Publish data every 1 seconds (1000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 1000) {
		lastMillis = millis();
		//Cayenne.virtualWrite(0, lastMillis);

  if(digitalRead(16)==LOW)
  {
    Cayenne.virtualWrite(V6,"1"); 
    inputvoltage=HIGH;
  }
  else
  {
    Cayenne.virtualWrite(V6,"0");  
    inputvoltage=LOW;
  }
  
  if(digitalRead(5)==LOW)
  {
    Cayenne.virtualWrite(V1,"1"); 
    line=HIGH;
  }
  else
  {
    Cayenne.virtualWrite(V1,"0");  
    line=LOW;
  }

  if(digitalRead(4)==LOW)
  {
    Cayenne.virtualWrite(V2,"1");   
    battery=HIGH;
  }
  else
  {
    Cayenne.virtualWrite(V2,"0");
    battery=LOW;
  }

  if(digitalRead(13)==LOW)
  {
    Cayenne.virtualWrite(V3,"1");   
  }
  else
  {
    Cayenne.virtualWrite(V3,"0");
  }

  if(digitalRead(12)==LOW)
  {
    Cayenne.virtualWrite(V4,"1");   
  }
  else
  {
    Cayenne.virtualWrite(V4,"0");
  }
 }
}

//Control the UPS with a button that responds to the length of the button press.

CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());

  if (request.channel = 5)
  {
    String value;
    value = (String)getValue.asString();

    if (value == "1")
    {
      if (line==LOW && battery==LOW && inputvoltage==LOW)
      {
        digitalWrite(14, HIGH);
        delay(3500);
        digitalWrite(14, LOW);
        delay(1000);
        Cayenne.virtualWrite(V5,"0");
      }
      if (line==HIGH || battery==HIGH || inputvoltage==HIGH)
      {
        digitalWrite(14, HIGH);
        delay(1000);
        digitalWrite(14, LOW);
        delay(1000);
        Cayenne.virtualWrite(V5,"0");
      } 
    } 
  } 
}


 

Credits

Tadeas Dvoracek

Tadeas Dvoracek

10 projects • 41 followers

Comments