Categories

Archives

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

EMON

Code

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
// SICC_EMON v2

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

String ResponseControl(void);
const char* ssid =”pichet-wifi”;
const char* password =””;

#include “EmonLib.h” // Include Emon Library
EnergyMonitor emon1; // Create an instance

ESP8266WiFiMulti WiFiMulti;

void setup()
{
Serial.begin(9600);

emon1.current(1, 111.1); // Current: input pin, calibration.
for(uint8_t t = 4; t > 0; t–) {
Serial.printf(“[SETUP] WAIT %d…\n”, t);
Serial.flush();
delay(1000);
}

WiFiMulti.addAP(ssid, password);

}

void loop() {
String data_send;

double Irms = emon1.calcIrms(1480); // Calculate Irms only

Serial.print(Irms*230.0); // Apparent power
Serial.print(” “);
Serial.println(Irms); // Irms

// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;

Serial.print(“[HTTP] begin…\n”);
data_send = “http://182.93.155.51/emon/collector.php”;
data_send += “?dev=1&password=A1101”;
data_send += “&value=” + String(Irms);
http.begin(data_send); //HTTP

Serial.print(“[HTTP] GET…\n”);
// start connection and send HTTP header
int httpCode = http.GET();

// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf(“[HTTP] GET… code: %d\n”, httpCode);

// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf(“[HTTP] GET… failed, error: %s\n”, http.errorToString(httpCode).c_str());
}

http.end();
}

delay(15*1000); // every 15 sec
}

Leave a Reply