Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:iot:current [2017/09/22 08:45] – created Somepuben:iot:current [2017/09/22 09:02] (current) – removed Somepub
Line 1: Line 1:
-<code c> 
-#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); 
-  } 
- 
-} 
- 
-<code> 
  
en/iot/current.1506069920.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
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