This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot:current [2017/09/22 08:46] – Somepub | en:iot:current [2017/09/22 09:02] (current) – removed Somepub | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <code c> | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include " | ||
| - | #include < | ||
| - | |||
| - | #define ADC_PIN A0 | ||
| - | |||
| - | EnergyMonitor emon1; | ||
| - | Ticker adcTicker; | ||
| - | |||
| - | bool adcFlag; | ||
| - | |||
| - | uint16_t adcSampleCount; | ||
| - | |||
| - | void setAdcFlag() | ||
| - | { | ||
| - | adcFlag=true; | ||
| - | } | ||
| - | |||
| - | void iot_connected() | ||
| - | { | ||
| - | Serial.println(" | ||
| - | iot.log(" | ||
| - | } | ||
| - | |||
| - | void setup() | ||
| - | { | ||
| - | Serial.begin(115200); | ||
| - | Serial.println(" | ||
| - | iot.printConfig(); | ||
| - | iot.setup(); | ||
| - | |||
| - | emon1.current(ADC_PIN, | ||
| - | adcSampleCount = iot.cfg-> | ||
| - | |||
| - | adcTicker.attach(0.5, | ||
| - | } | ||
| - | |||
| - | void loop() | ||
| - | { | ||
| - | iot.handle(); | ||
| - | |||
| - | if(adcFlag) | ||
| - | { | ||
| - | adcFlag = false; | ||
| - | double val = emon1.calcIrms(adcSampleCount); | ||
| - | String msg = String(val); | ||
| - | iot.publishMsg(" | ||
| - | Serial.println(msg); | ||
| - | } | ||
| - | |||
| - | } | ||
| - | |||
| - | < | ||