This is an old revision of the document!
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 side 3,5 mm jacket input(smaller input jacket). The controller and sensor modules must be connected.
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); } }