Current example

The current sensor device has to be connected to the sensor module. Current sensor device has a 3,5 mm plug what has to be connected to the sensor module left jacket A. The controller and sensor modules must be connected. The current sensor has to be 30A

Needed libraries:

lib_deps = ITTIoT, EmonLib

The example code above shows the alternating current value to current topic “curr”. If nothing is measured the current value is NaN.

#include <Arduino.h>
#include <ittiot.h>
#include "EmonLib.h"
#include <Ticker.h>
 
#define ADC_PIN A0
 
EnergyMonitor emon1;
Ticker adcTicker;
 
bool adcFlag;
 
uint16_t adcSampleCount;
 
void setAdcFlag()
{
    adcFlag=true;
}
 
void iot_connected()
{
    Serial.println("MQTT connected callback");
    iot.log("IoT current example!");
}
 
void setup()
{
    Serial.begin(115200);
    Serial.println("Booting");
    iot.printConfig(); // print json config to serial
    iot.setup();
 
    emon1.current(ADC_PIN, iot.cfg->get<double>("stc"));             // Current: input pin, calibration.
    adcSampleCount = iot.cfg->get<uint16_t>("samples");
 
    adcTicker.attach(0.5, setAdcFlag);
}
 
void loop()
{
  iot.handle();
 
  if(adcFlag)
  {
      adcFlag = false;
      double val = emon1.calcIrms(adcSampleCount);
      String msg = String(val);
      iot.publishMsg("curr", msg.c_str());
      Serial.println(msg);
  }
 
}
en/iot/examples/current.txt · Last modified: 2018/09/05 10:00 by tomyKalm
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0