#include "EmonLib.h"
EnergyMonitor emon1;
char ssid[] = "ISI DENGAN SSID WIFI";
char pass[] = "ISI PASSWORD WIFI";
int status = WL_IDLE_STATUS;
WiFiClient client;
char server[] = "agnosthings.com";
void setup()
{
Serial.begin(9600);
emon1.current(5, 60); // Current: input pin, calibration.
emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
}
delay(5000);
}
void loop()
{
emon1.calcVI(20,2000);
unsigned int long timemillis=millis(); //keeping the track of the time since the device is switched ON
unsigned int long time=timemillis/1000;
float realPower = emon1.realPower;
float apparentPower= emon1.apparentPower;
float powerFactor= emon1.powerFactor;
float supplyVoltag = emon1.Vrms;
float Irms = emon1.Irms;
//displaying the values
Serial.println("Watt : ");
Serial.println(realPower);
String kwh = "";
kwh+=String(int(realPower))+ "."+String(getDecimal(realPower));
String url_api = "ganti dengan url api dari agnosthings.com ?push=kwh={tmpval}";
url_api.replace("{tmpval}", kwh);
boolean requestStatus = httpRequest(url_api);
if(requestStatus == true)
Serial.println("Sending data success! Suhu " +stringVal +" Pakan " + pakan);
else
Serial.println("Sending data failed!");
Serial.println();
client.stop();
delay(1000);
}
boolean httpRequest(String link) {
// if you get a connection, report back via serial:
Serial.println("Push data to server");
if (client.connect(server, 80)) {
// Make a HTTP request:
client.println("GET " + link + " HTTP/1.0");
client.println("Host: agnosthings.com");
client.println();
return true;
} else {
// You couldn't make the connection
Serial.println("Connection Failed");
client.stop();
return false;
}
}