Integrating Emoncms into ESP modules

Hi all!, am Juan, from Spain, Im using emonlib on Arduino for a long time and works very well, ty for your work people, this is an awesome project!. I have multiple dashboards too. Im developer on Souliss project and I worked for a long time to have a complete domotic system under arduino and opensource. Now we can load the Framework on a ESP module, so we've easy and cheap modules to make a WIFI domotic system.

I come to the forum to integrate this awesome library to ESP. Any help is appreciated.

Regards!!

 

Paul Reed's picture

Re: Integrating Emoncms into ESP modules

Please change the title of your post to represent what you are trying to achieve.
>> Por favor cambia el título de su puesto para representar lo que usted está tratando de lograr

​Paul (Moderator}

juanpintom's picture

Re: Integrating Emoncms into ESP modules

Sorry, Its my first post on the forum and the target of this post its just for introduce myself. Im trying to integrate emonlib on a ESP module but I opened a new post for this purpose. This title is ok? if you suggest me other title I'll change, no problem. 

Sorry for the inconvenience, Regards! :P

Paul Reed's picture

Re: Integrating Emoncms into ESP modules

What about 'integrating emoncms into ESP modules'?
Then if someone else has a similar interest, they will find it easier to search, find and contribute to your post.

Paul

juanpintom's picture

Re: Integrating Emoncms into ESP modules

This are the two functions that I need to modify to get it working over an ESP. I'll work on it.

 

double EnergyMonitor::calcIrms(unsigned int Number_of_Samples)
{
 
   #if defined emonTxV3
   int SupplyVoltage=3300;
   #else
   int SupplyVoltage = readVcc();
   #endif

 
  for (unsigned int n = 0; n < Number_of_Samples; n++)
  {
    sampleI = analogRead(inPinI);

    // Digital low pass filter extracts the 2.5 V or 1.65 V dc offset,
   //  then subtract this - signal is now centered on 0 counts.
    offsetI = (offsetI + (sampleI-offsetI)/1024);
   filteredI = sampleI - offsetI;

    // Root-mean-square method current
    // 1) square current values
    sqI = filteredI * filteredI;
    // 2) sum
    sumI += sqI;
  }

  double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
  Irms = I_RATIO * sqrt(sumI / Number_of_Samples);

  //Reset accumulators
  sumI = 0;
//--------------------------------------------------------------------------------------       
 
  return Irms;
}

long EnergyMonitor::readVcc() {
  long result;
 
  //not used on emonTx V3 - as Vcc is always 3.3V - eliminates bandgap error and need for calibration http://harizanov.com/2013/09/thoughts-on-avr-adc-accuracy/

  #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 
  #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_AT90USB1286__)
  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  ADCSRB &= ~_BV(MUX5);   // Without this the function always returns -1 on the ATmega2560 http://openenergymonitor.org/emon/node/2253#comment-11432
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
  ADMUX = _BV(MUX3) | _BV(MUX2);
   
  #endif

  #if defined(__AVR__)
  delay(2);                                        // Wait for Vref to settle
  ADCSRA |= _BV(ADSC);                             // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = READVCC_CALIBRATION_CONST / result;  //1100mV*1024 ADC steps http://openenergymonitor.org/emon/node/1186
  return result;
 #elif defined(__arm__)
  return (3300);                                  //Arduino Due
 #else
  return (3300);                                  //Guess that other un-supported architectures will be running a 3.3V!
 #endif
}

hanguyen's picture

Re: Integrating Emoncms into ESP modules

in video is my AC monitor with Wifi chip esp 8266
https://www.youtube.com/watch?v=yTG6C0ULMuc

hanguyen's picture

Re: Integrating Emoncms into ESP modules

you can see it more clearly here
https://www.youtube.com/watch?v=hPhFvFyTp6w

juanpintom's picture

Re: Integrating Emoncms into ESP modules

Can you share the code and the wiring with the Esp? are you using an arduino? I want to read directly from the Esp ADC pin (0-1v) I use actually on Arduino with a 220ohm burden resistor and I calibrate via software using 10 instead the 111.1 from the example on the library.

Regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.