EmonTX arduino shield without emonpi to domotic box directly, possible?

Hello!

First sorry for my bad english…

I discovered openenergymonitor, great project, thank you!

I mounted my arduino emontx shield and it works well.

Now my goal is to send directly data (power, IRMS …) to my domotic home box (jeedom like home assistant, domoticz) without using emonpi (to avoid other hardware).

Is it possible? If yes can you give me the solution? (433/868Mhz RFM69CW (HopeRF) wireless transceiver is compatible with rfxcom / rflink 433Mhz?)

Thank you!

I think it has been done before now. You could start by searching the forum for rfxcom, there are a couple of discussions (Search results for 'rfxcom' - OpenEnergyMonitor Community).

An other possibility is to use an emonESP, significantly cheaper than a emonPi and it could allow you to use MQTT over WiFi if they are available. (I know you said without other HW but a EmonESP/ Huzzah is only a small addition)

Thank you pb66 for your reply!

I don’t find any interresting pst for interfacing emontx shield with rflink/rfxcom directly…

For the second point yes I would like to install a emonesp/huzzah but it’s only for emontx v3 and no emontx arduino shield, isn’t it?

thank you!

Ok I found this old thread :
https://openenergymonitor.org/forum-archive/node/11571.html

It seems to work!

What do you think about this?

It has been used with the emonTx shield before now, again there is a discussion about it out there somewhere, I do not recall when/where unfortunately

I just had a quick search and could not find the post I’m thinking of. Someone has had a JeeLIb device talking to a RFX connected base. the detail escapes me but I’m sure it’s been done if you are willing to do some coding, it isn’t compatible “out of the box” no.

I’m sure there must be more recent posts, but AFAIK there is nothing special about using a emonESP with a shield, the 6 pin header is exactly the same for a shield or a plain emonTx v3.4. All you need to do is be sure what ever sketch you use on the shield, it prints the serial data in the same “emonESP” format as the emonTx does and doesn’t print loads of other stuff to the serial port to confuse the emonESP.

Thank you pb66 for the link!

I Will search some other link, and i will post reply

Hi!

OK so I found some links and I think I have a solution.

  1. First I must buy :
  • FT232RL for input sketch in the ESP
  • ESP12e
  1. With FT232RL put into the ESP this sketch:
    https://github.com/palitu/emonTX-ESPGateway

  2. After, I solder ESP12e instead of RFM69CW on the emontx arduino shield like that :

Why I must change value resistor for R7 and R20 (it’s “TX” pin)?

  1. And finaly I use this sketch on arduino uno :
    https://openenergymonitor.org/forum-archive/node/11571.html

With that the arduino shield send mqtt data on wifi and I will can receive these data on my domotic box (domotics, jeedom…)

Do you think it’s ok? Any things I forgot?

Thank you in advance (and sorry for my bad english again…)

This is not what I had in mind. Are you trying to do something out of the ordinary? For example is there a need to use spi or something else I’m missing?

Using an ESP with an emonTx is an everyday thing, nothing special and using a ESP with an emonTx shield is just as easy, it’s just not as well documented and the sketches have not yet been converted for use with an ESP, but those changes are just editing the serial output format nothing more.

If you do use a generic esp8266 then you do need to add level matching to the job, but that stands whether you are using and emonTx or and emonTx shield.

However if you use a Huzzah (or shop bought emonESP) they are not expensive but they do have the level matching already taken care of and can also be powered from 5v. This means you are not causing dips in the 3V3 rail during transmission.

If you do have a Huzzah all you need to do is load the emonESP firmware from GitHub - openenergymonitor/EmonESP: ESP8266 WIFI serial to emoncms link (there is a full guide and yes you will need a serial programmer like an FTDI). Once you’ve done that you have an emonESP as sold in the shop (minus the link wires). There is no physical difference. So from here on I will just refer to an emonESP.

Which ever emontx shield sketch you chose to use, all you need to do is ensure the print output prints key:value pairs and nothing else before you flash it to the Arduino you are using with the shield.

So assuming you have a working emonESP and you’ve loaded you edited sketch to the Arduino attached to your shield. You just need to connect the gnd,5v,Rx and Tx of the emonESP header to the gnd, 5v, Rx and Tx of the emonTx shield 6way header.

That’s it done.

You do not need to solder anything (unless you choose to solder the 4 link wires) and you do not need to worry about resistors.

The threads you link and the git repo all seem to do things a different way, you can of course try that method if you choose, but there is a much simpler method that is more in keeping with what we do with the emonTx already. The help and support will be more readily available with this “normal” method.

Thank you very much!!!

In fact I had seen the emonesp but I thought it was reserved for emontx V3 and not the emontx shield … And I had not seen the 6-way output on the shield … Now I understood your answer! (by against the shop, ESP8266 WiFi is classified in “emontx v3” we can think that it is only for the v3 … ;-))
So if I buy an ESP8266 WiFi in the shop I do not need the programmer, everything is already in?
Finally I will have to modify the sketch arduino.

There is this modified sktech to send the data by wifi?

thank you again for taking the time to answer, it’s very nice!

Correct, the emonESP module (Huzzah) already has the emonESP firmware installed and since you are using an Arduino Uno? I’m guessing you are able to install the emonTx shield firmware via USB?

However IMO it’s always handy to have a USB-Serial programmer handy when you playing with this stuff, so whilst strictly speaking you shouldn’t need it, if you want (need?) to update the emonESP firmware or modify it yourself, you’ll need one. Or if you need to debug the emonESP to shield comms, if you have a USB-serial programmer you can just separate the ESP and shield and connect the USB-serial adaptor to see what the output is from the shield or connect it to the esp to write data to it in place of the shield. It’s up to you. I would rather have one and not need it, than need it and not have one.

The sketch does not need to be “modified to send the data by wifi” per se, it just needs the serial output changed to key:value pairs so that the emonESP can read it without modification to the esp fw.

Have you got a working shield sketch? If so which one are you using? It will already be printing the data to serial, you just need to format it slightly differently. Nothing major. Without seeing the sketch you want to use (or refreshing my memory on the exact requirements of the emonESP) it difficult to tell you exactly what needs to be changed, but it will be easy (famous last words :smile:.

Thank you for your answers and your patience.

Ok I’ll take a programmer for the esp.

For the sketch Shield_CT1234_Voltage.ino
Which line of the sketch is concerned by “priting the data to serial”?

If you can tell me what change in the program, it would be very nice!

For my culture, in the sketch of the ESP, which line indicates the serial reading of the data?

thank you!

if you wish to modify your sketch to include this line for each input

 Serial.print("cmd_1("); Serial.print(emontx.power1); Serial.println(")");

next input line at next ct

   Serial.print("cmd_2("); Serial.print(emontx.power2); Serial.println(")");

then install this on your esp - there some extra code as the esp i use has rgb on it and i use the lights to tell me if there is an error condition

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
 //int blue = 1;
 //int red = 2;
 //int grn = 4;
 // Update these with values suitable for your network.
 String command;
 float input1b = 0;
float input2b = 0;
float input3b = 0;
int scan1;
int scan2;
int scan3;

 const char* ssid = "IOT";
 const char* password = "";
const char* mqtt_server = "192.168.168.150";
String clientName;
WiFiClient espClient;
PubSubClient client(mqtt_server,1883, espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
char msg2[50];
char msg3[50];

void callback(char* topic, byte* payload, unsigned int length) {
 // handle message arrived
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);

}
}

String macToStr(const uint8_t* mac)
{
 String result;
 for (int i = 0; i < 6; ++i) {
result += String(mac[i], 16);
if (i < 5)
result += ':';
 }
 return result;
}


void setup() {
Serial.begin(9600);
 pinMode(BUILTIN_LED, OUTPUT); 
// pinMode(red, OUTPUT);
 //pinMode(blue, OUTPUT);

delay(10);
digitalWrite(BUILTIN_LED, HIGH); 
 setup_wifi();



 // put your setup code here, to run once:
Serial.println("started");
}

void setup_wifi() {


 delay(10);
 // We start by connecting to a WiFi network
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);
WiFi.hostname("GridMonitor");
 WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }

 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
   Serial.println(WiFi.localIP());

   clientName += "esp8266-";
  uint8_t mac[6];
 WiFi.macAddress(mac);
 clientName += macToStr(mac);
 clientName += "-";
clientName += String(micros() & 0xff, 16);

Serial.print("Connecting to ");
Serial.print(mqtt_server);
Serial.print(" as ");
Serial.println(clientName);

MQTT_Connect();

}


void MQTT_Connect(){
if (client.connect((char*) clientName.c_str())) {
 Serial.println("Connected to MQTT broker");

   digitalWrite(BUILTIN_LED, LOW); 

  }
 else {
Serial.println("MQTT connect failed");
Serial.println("Will reset and try again...");

abort();
  }
  client.setCallback(callback);
 }

void loop() 
{
  if(WiFi.status() != WL_CONNECTED){setup_wifi();}
  if (!client.connected()) { MQTT_Connect(); }
  client.loop();

   if(Serial.available())
  {
 char c = Serial.read();

  if (c == ')')
 {

    parseCommand(command);

     command="";
   }
   else
   {
  command += c;
  digitalWrite(BUILTIN_LED, HIGH); 
 }
 }

}

void parseCommand(String com)
{

char test[5];
 String part1;
 String part2;

  part1 = com.substring(6, com.indexOf("("));

 Serial.println(part1);

  part2 = com.substring(com.indexOf("(")+1);
  Serial.println(part2);
  if (part1 == "1")
  {

 scan1++;
Serial.println("recieved 1");
String raw_CMD;

   float input1 = part2.toFloat();
 input1b = input1b+ input1;
 if (scan1==5){
 scan1=0;
 input1 = input1b/5;
 input1b=0;
 raw_CMD=input1;
 if (client.connected()){
 Serial.print("Sending payload: ");
 Serial.println(raw_CMD);
  if (client.publish("/invert", (char*) raw_CMD.c_str())) {
   digitalWrite(BUILTIN_LED, LOW); 
   Serial.println("Publish ok");
   // digitalWrite(BUILTIN_LED, HIGH);
 }
  else {
  Serial.println("Publish failed");
 }
 }
 }

 }
 if (part1== "2")
{
 scan2++; 
 Serial.println("recieved 2");
String raw_CMD;

 float input2 = part2.toFloat();
input2b = input2b+ input2;
if (scan2==5){
  scan2=0;
 input2 = input2b/5;
 input2b=0;
 raw_CMD=input2;
 if (client.connected()){
 Serial.print("Sending payload: ");
 Serial.println(raw_CMD);
  if (client.publish("/grid", (char*) raw_CMD.c_str())) {
  digitalWrite(BUILTIN_LED, LOW); 
   Serial.println("Publish ok");
   // digitalWrite(BUILTIN_LED, HIGH);
  }
  else {
   Serial.println("Publish failed");
 }

 }
 }
 }
 if (part1 == "3")
 {
  scan3++; 
  Serial.println("recieved 3");
  String raw_CMD;

  float input3 = part2.toFloat();
   input3b = input3b+ input3;
  if (scan3==5){
  scan3=0;
  input3 = input3b/5;
  input3b=0;
  raw_CMD=input3;
   if (client.connected()){
  Serial.print("Sending payload: ");
    Serial.println(raw_CMD);
   if (client.publish("/wind", (char*) raw_CMD.c_str())) {
  // digitalWrite(BUILTIN_LED, HIGH); 
   Serial.println("Publish ok");
   digitalWrite(BUILTIN_LED, LOW);
   }
  else {
   Serial.println("Publish failed");
  }
  }
 }  

   }
 delay(100);
}  

it will send to topics /invert , /grid and /wind ( you can change that to whatever topic you want ) I also only used 3 cts a I needed to use ct4 to be able to use lcd screen locally if you wish to use all 4 cts just add the 4th block
then you can use dolomitz to watch for mqtt inputs… it also collect 5 inputs from emontx shield and adds them together and divides to get an average - which is a mqtt send about every 2-3 seconds

I prefer to use the mega r3 then you just write cmd_1, cmd_2 …etc to serial port 2 to be read by built in esp then you can leave debug code in on mega
or you can use uno r3 but you can not leave in any debugging code…

Hello stephen krywenko, thank you very much for your reply!

OK so I will modify my sketch for emontx shield with your exemple.

For the esp sketch, I don’t understand… I must modify esp preload (from energymonitor)? Or I can use ageneric ESP12e (with 3.3V VCC and not 5V VCC)?

Thank you!

I think @stephen is confusing things somewhat. What he is suggesting is NOT what we have been discussing until now and it is NOT the standard emonESP and emonTx (shield) way.

You can of course follow what ever advice you chose, but to avoid confusion I would suggest stick to a particular path, further more I would also suggest sticking the the more well trodden path. If you have any problems with stock emonESP and stock shield firmware with minor mods, there are many OEM’ers about to help you.

Please let us know what you want to do, I will leave you with Stephen if you prefer his approach. Otherwise I will try to look at your sketch later this evening (I’ve just got home and need to eat etc).

Just to be clear, I’m not part of Megni (the OEM shop) I just volunteer on the forum so I have no vested interest in the purchases you make in the shop. However, although you can buy them cheaper elsewhere, it does help support the open source project if you do buy from the OEM shop.

Hello Paul!

sorry for the confusion … My goal is simply to transfer my data emontx shield to wifi / mqtt … Yesterday I discovered that the emonesp module was compatible emontx shield … I’m taking any help including yours of course ;-). I would do the simplest method to set up … So if you want to tell me what I have to change in the sketch of my previous post. Thank you!

By the way I also keep the solution of Stephen who I think can use generic material.

Thank you to you Paul and stephen!

If you want to make a start yourself it looks simple enough.

You need to delete/comment out lines 98, 103, 108 and 113. Then replace line 117 with this section from the current emonTx v3.4 sketch (emontx3/firmware/src/src.ino at 3.1.0 · openenergymonitor/emontx3 · GitHub) edited slightly for you sketch as

Serial.print("ct1:"); Serial.print(emontx.power1);
Serial.print(",ct2:"); Serial.print(emontx.power2);
Serial.print(",ct3:"); Serial.print(emontx.power3);
Serial.print(",ct4:"); Serial.print(emontx.power4);
Serial.println();
delay(50);

this should regularly output serial like so (once the initial setup prints have finished)

ct1:123,ct2:456,ct3:789,ct4:123

and the emonESP as it comes will accept this input. You can of course use more specific names instead of ct1 etc, those custom names will be passed through to emoncms or MQTT.

The need to match levels is purely a hardware matter, if you use Huzzah or emonESP (or similar) that has on board level matching and a built in voltage regulator, then you can install emonESP or Stephen’s FW or many others and it will physically connect to a shield ok, If you get a generic esp8266, it will not have the level matching and will only accept 3.3v power and IO. Your choice of HW and your choice of FW are independent and largely unrelated. Using a different sketch will not enable you to use a generic esp8266.

sorry if there was confusion introduced- was not my intent-- he was asking for an easy way to get data to dolomitz … and my way quite easy with mega r3 or uno r3 – and the emontx shield as no soldering in stuff required (or with uno/mega with an esp that is 5volt ready ( Huzzah, esptoy, wemos mini … etc))… just flash it with my serial com reader to mqtt… the hardest part is figuring out what serial port you are using - whether a hardware or software serial…

as to generic ESP if it the very basic one with out voltage regulator the 3.3 will have to be used, but the amps are not normally high enough on the 3.3 rail of most uno type boards to support esp properly , so it will be flaky when it comes to the wireless (most likely would have to build/buy yourself an generic esp voltage regulator to bring it up to 5 volt) … if it a generic esp with 5 volt power regulator ( they usually have direct usb connector or FTDI pins - so can flash them directly ) then you can connect them directly to the 5 volt rail of the uno/mega to the 5 volt pin on the esp usually with out issue –

Hello everybody!

Thank you all for your reply!

@pb66 : So this modifications are ok?(I think not … :frowning: )

And with that, I just plug espemon pre-programmed of energymonitor on the emontx shield and it’s ok?Nothing else to do? the shield will “connected” to the espemon?

@stephen : Don’t worry stephen it’s very friendly t help me! And I found one of your topic of monitoring power, good work!

I think I will buy emonesp pre-programmed it’s much easy for me :wink:

Thank you again for your reply!

the yellow section is important if you x it out on purpose – move your box to line 146 is the more likely location