#include <ModbusTCPSlave.h>
#include <Ticker.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
//Settings IP Nodemcu
byte ip[] = { 192, 168, 43, 187};
byte gateway[] = { 192, 168, 43, 1 };
byte subnet[] = { 255, 255, 255, 0 };
ModbusTCPSlave Mb;
Ticker Stop;
const int ledPin = 4;
const int inputPin = 12;
//const int analogInPin = A0;
void monitoring() {
double Irms = emon1.calcIrms(1480);
///Digital Inputs
Mb.MBHoldingRegister[0]=digitalRead(inputPin);
///Digital Outputs
digitalWrite(ledPin,Mb.MBHoldingRegister[1] );
////Analog Input
Mb.MBHoldingRegister[2] = Irms *100;//scaling 0.01
}
void setup()
{
emon1.current(0, 65.1);
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(115200);
Mb.begin("puaks.blogspot.com", "puakpipop", ip, gateway, subnet);
delay(100);
}
void loop()
{
Mb.Run();
Stop.attach_ms(25,monitoring);
}
mantul mas, semoga menjadi amal jariyah di akherat
BalasHapusaamiin....
Hapussudah dcoba?