ESP8266 (NoceMCU), EPEver Tracer A and MAX485 module

My current code is split into 12 tabs in my Arduino IDE project, so isn’t really suitable for sharing here.

However, I do have some earlier code which worked, but not as well as the code I posted above because trying to read all the registers at once doesn’t work well.

I’d suggest that you just try reading one group of registers (such as the 8 registers starting at 0x3100) as a test.

But, first things first, are you powering your MAX485 module with 5V from your Wemos? (Powering it from the Tracer didn’t work for me)
Are the lights on on the MAX485 and does one of then flash when you try to take a reading?

Also, without an FTDI, debugging is very difficult! The Rx pin on the FTDI connects to pin D4 on the D1 Mini (GPIO2) and the GND connection should connect to the GND on the board.

Here’s my basic (early) code…

#include <ModbusMaster.h>      //https://github.com/4-20ma/ModbusMaster/
 #include <ESP8266WiFi.h>
 #include <SimpleTimer.h>      // Non-blocking timer
 #include <PubSubClient.h>     // https://github.com/knolleary/pubsubclient
 
 #define MAX485_DE       D2
 #define MAX485_RE       D1

 #define PANEL_VOLTS     0x00
 #define PANEL_AMPS      0x01
 #define PANEL_POWER_L   0x02
 #define PANEL_POWER_H   0x03
 #define BATT_VOLTS      0x04
 #define BATT_AMPS       0x05
 #define BATT_POWER_L    0x06
 #define BATT_POWER_H    0x07
 #define LOAD_VOLTS      0x0C
 #define LOAD_AMPS       0x0D
 #define LOAD_POWER_L    0x0E
 #define LOAD_POWER_H    0x0F

// Added by PK...
 #define CONTROL_TEMP   0x11
 #define BATT_TEMP      0x10 // Remote Battery Temp. If 0x1B not working then try 0x10
 #define BATT_SOC       0x1A // Battery State of Charge (Percentage)

// #define HB D4

// Initialise ModbusMaster object
ModbusMaster node;

// Initialise the timer object
SimpleTimer timer;


const char* ssid = "REDACTED";
const char* pass = "REDACTED";

IPAddress ip            (REDACTED, REACTED, REDACTED, REACTED);          //Static IP Address for the device
IPAddress gateway       (REDACTED, REACTED, REDACTED, REACTED);
IPAddress subnet        (REDACTED, REACTED, REDACTED, REACTED);

IPAddress MQTTserver    (REDACTED, REACTED, REDACTED, REACTED);       // IP Address for the MQTT Server...

WiFiClient My_WiFi_Client;

PubSubClient MQTTclient(My_WiFi_Client);


void setup()
{
  WifiConnect(); 

  MQTTclient.setServer(MQTTserver, REDACTED);
  MQTTconnect();

  
//  WiFi.begin(ssid, password);

  Serial1.begin (74880);
  Serial1.println("Serial1 Initialised");
  
  Serial.begin(115200); // DO NOT CHANGE!

  pinMode(MAX485_RE, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  // Init in receive mode
  digitalWrite(MAX485_RE, 0);
  digitalWrite(MAX485_DE, 0);

  // EPEver Device ID 1
  node.begin(1, Serial);

  // Callbacks 
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

timer.setInterval(2000, readMODBUS);

}


void readMODBUS()
{
  uint8_t result;

  // Read 20 registers starting at 0x3100)
  node.clearResponseBuffer();
  result = node.readInputRegisters(0x3100, 20); 

  if (result == node.ku8MBSuccess)
  {
    float pV = node.getResponseBuffer(PANEL_VOLTS)/100.0f;
    float pI = node.getResponseBuffer(PANEL_AMPS)/100.0f;
    float pP = (node.getResponseBuffer(PANEL_POWER_L) |
                    (node.getResponseBuffer(PANEL_POWER_H) << 8))/100.0f;

    float bV = node.getResponseBuffer(BATT_VOLTS)/100.0f;
    float bI = node.getResponseBuffer(BATT_AMPS)/100.0f;
    float bP = (node.getResponseBuffer(BATT_POWER_L) |
                    (node.getResponseBuffer(BATT_POWER_H) << 8))/100.0f;

    float lV = node.getResponseBuffer(LOAD_VOLTS)/100.0f;
    float lI = node.getResponseBuffer(LOAD_AMPS)/100.0f;
    float lP = (node.getResponseBuffer(LOAD_POWER_L) |
                    (node.getResponseBuffer(LOAD_POWER_H) << 8))/100.0f;

// Added by PK
    float bT = node.getResponseBuffer(BATT_TEMP)/100.0f;
    float bSOC = node.getResponseBuffer(BATT_SOC)/100.0f;
    
    float cT = node.getResponseBuffer(CONTROL_TEMP)/100.0f;   
                    
                    
    Serial1.print("VPanel: ");
    Serial1.println(pV);
    Serial1.print("IPanel: ");
    Serial1.println(pI);
    Serial1.print("PPanel: ");
    Serial1.println(pP);
    Serial1.println();

    Serial1.print("VBatt: ");
    Serial1.println(bV);
    Serial1.print("IBatt: ");
    Serial1.println(bI);
    Serial1.print("PBatt: ");
    Serial1.println(bP);                    
    Serial1.print("TBatt: ");
    Serial1.println(bT);
    Serial1.print("SOC  : ");
    Serial1.println(bSOC);         
    Serial1.println();
    
    Serial1.print("VLoad: ");
    Serial1.println(lV);
    Serial1.print("ILoad: ");
    Serial1.println(lI);
    Serial1.print("PLoad: ");
    Serial1.println(lP);   
    Serial1.println();
    Serial1.print("CTemp: ");    
    Serial1.println(cT);    
    
    Serial1.println();
    Serial1.println();

    MQTTclient.publish("REDACTED/REDACTED/Panel_Output_Voltage",String(pV).c_str(),true);   
    MQTTclient.publish("REDACTED/REDACTED/Panel_Output_Current",String(pI).c_str(),true);   
    MQTTclient.publish("REDACTED/REDACTED/Panel_Output_Wattage",String(pP).c_str(),true);
    MQTTclient.loop();    
    MQTTclient.publish("REDACTED/REDACTED/Battery_Voltage",String(bV).c_str(),true);   
    MQTTclient.publish("REDACTED/REDACTED/Battery_Charge_Current",String(bI).c_str(),true);   
    MQTTclient.publish("REDACTED/REDACTED/Battery_Charge_Wattage",String(bP).c_str(),true);
    MQTTclient.publish("REDACTED/REDACTED/Battery_Temperature",String(bT).c_str(),true);      
    MQTTclient.publish("Spain/Solar_Monitor/Battery_SOC",String(bSOC).c_str(),true);
    MQTTclient.loop();   
    MQTTclient.publish("REDACTED/REDACTED/Load_Voltage",String(lV).c_str(),true);   
    MQTTclient.publish("REDACTED/REDACTED/Load_Current",String(lI).c_str(),true);
    MQTTclient.publish("REDACTED/REDACTED/Load_Wattage",String(lP).c_str(),true);   
    MQTTclient.loop();   
    MQTTclient.publish("REDACTED/REDACTED/Controller_Temerature",String(cT).c_str(),true);           
    
  } else {
    Serial1.print("Bad Read, ret val:");
    Serial1.println(result, HEX);

    // Result codes:
    // 00 Success
    // 01 Illegal function Error
    // 02 Illegal Data Address Error
    // 03 Illegal Data Value Error
    // E0 Invalid Response Slave ID Error
    // E1 Invalid Response Function Error
    // E2 Response Timed-Out Error
    // E3 Invalid Response CRC Error
   }
}


void loop()
{
  timer.run();

  if (!MQTTclient.connected())
  {
    MQTTconnect();
  }
  MQTTclient.loop();

    if(WiFi.status() != WL_CONNECTED)
  {
    WifiConnect(); 
  }
}

void WifiConnect()
{
  WiFi.begin(ssid, pass);
  WiFi.config(ip, gateway, subnet);
  WiFi.mode(WIFI_STA);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial1.print(".");
  }
} // End of void WiFiConnect


void MQTTconnect()
{
  // Loop until we're connected
  while (!MQTTclient.connected())
  {
    int reason=MQTTclient.state();
    Serial1.print("MQTT Disconnection reason = ");
    Serial1.println(reason);  
    
    
    Serial1.print(F("Attempting MQTT connection..."));
    // Attempt to connect
    if (MQTTclient.connect("REDACTED", "REDACTED", "REDACTED"))
    {
      Serial1.println(F("MQTT Connected"));        
      // Once connected, publish an announcement...
      MQTTclient.publish("REDACTED/REDACTED/REDACTED","ALIVE");      
      MQTTclient.loop();
    }
      // ... and subscribe or re-subscribe

    else  // We get here if the MQTT Connect failed....
    {
      Serial1.print(F("failed, rc="));
      Serial1.print(MQTTclient.state());
      Serial1.println(F(" try again in 1 seconds"));
      // Wait 1 second before retrying
      delay(1000);
    }
  }  
} // End of function MQTTconnect


void preTransmission()
{
  digitalWrite(MAX485_RE, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE, 0);
  digitalWrite(MAX485_DE, 0);
}

Pete.

1 Like

Thanks for the code. As of now, I don’t have the FTDI I will have to modify your code and try to parse the data to ThingSpeak or Blynk.
Regarding the FTDI, what type are you using? There are different types so I’m not sure what type can work. Are one of these two devices suitable?

Regarding powering the MAX485, I use Wemos 5V and GND pins, powering from the tracer was the next step in my mind (I checked and the first 2 wire are giving 4.5V the orange/white and orange wires of the ethernet cable).

On my MAX485 there is only one LED and when I connect the 5V and GND it’s steady lightning no mether if I try to get the reading or not. I can see a flashing only when I connect the pins DI, DE, DE, RO, and GND to the Wemos and not connecting the 5V. It’s that “normal” behaving or not?

Paolo

I use this type of FTDI…

I think my MAX485 has a power and “activity” LEDs and that the “activity” one flashes when a reading is taken, but I’d need to check.

Pete.

Just checked, and the 485 modules that I’m currently using just have a power LED.

Another thought, are you sure that you’ve connected the RJ45 connections correctly?

Pete.

Do you mean the RJ45 to the A and B of the MAX485? I was forwarding the instruction of this PDF, nevertheless, I did try to invert the wire - no success.

I suppose this LED on your MAX485 is always on as mine, am I right?

So I was thinking about how to connect to the Serial1, and not to wait for the FDTI adapter from China (because it will take more than a month to come to my country), and in the end, I figured out I can use the original CC-USB-4S485-150U EPever cable for debugging :slight_smile:

I connected to the D4 and GND as you instructed (to the CC-USB) and I can read the Serial1.

Now, I did try to install this MQTT client to my PC (mosquitto) and to get the Wemos connected to it, but as the MQTT and this mosquitto it’s a bit confusing to me I ended commenting the whole part regarding the MQTT in your code.
If I understand well you were using the MQTT just to communicate (forward) the result to “into the world” - am I right? Anyhow, I don’t need this for this my test purpose.
As my solar charge controller is on a remote site, I can’t test it today. If the weather condition will be OK I will test it Friday evening and let you know the result.

One more question - do you connect as follow:
DI of the MAX485 to the TX of the Wemos and
RO of the MAX485 to the RX of the Wemos?

Thank you very much for now.
Paolo

Yes, that diagram at the end is correct. However, I’m assuming that you’ve chopped-up a network cable to wire this up, so you should take a very careful look at the colours of the wires as they are connected in the plug, and ensure that you are actually using the correct ones at the other end.

Yes.

Good thinking!

That’s correct. I have a a Raspberry Pi running Mosquitto and Node-Red. I have the Blynk plug-in for Node-Red installed, which gives me my Blynk connectivity as well as Alexa integration etc. You don’t need that if you are viewing the results in the serial monitor.

Yes…


Pete.

1 Like

Thank you for your reply.
While I waiting I was looking into the detail of the tekk code and the one you shared. The “core” part is almost the same, the only thing I see is a slight difference in the approach of the registers reading. Hopefully, this different approach will make the ketch. I’ll let you know.
Paolo

Dear Pete
As I was really impatient, I found some gap in the schedule and went into the field to try the code you share on my Tracer.

It didn’t work at first giving me some “Bad Read” output.

I was powering the Wemos from the PC, and I tried to power it from the Tracer (connecting the orange pin the +5V). The Wemos got powered but I got some nonsense readings (see the picture below).


Then I tried to change the wires from the Tracer in the A and B slots, no result.
Then I put again the wires from the Tracer in the A and B slots as originally and connected the Wemos to the PC (powering the Wemos from the micro USB). And then bang - I started to get some “normal” readings :smiley: !!
I honestly don’t know why it didn’t work right away. Maybe some wire wasn’t connected properly? Don’t know… Anyway, thanks again for the code they shared!

The interesting thing is that when I tried to connect the micro USB cable to some power supply adapter (for phone charging 2A) I got again some nonsense reading, same as when I was trying to power the Wemos from the Tracer +5V pin and GND.

Seams like the only way to make it work from micro USB is to power it from the PC! Why?
I didn’t have with me the jack so to try to connect the Wemos from the proper power supply to test a “separate” power supply (I will try this too). This is now worrying me because if I cant manage to power it from some power source it’s unusable. I don’t understand what is behind such behavior.

I will now work on putting your code in the sketch from tekk code and a ThingSpeak connection too.

One more question. In an earlier post you put your code for powering on/off of the Tracer load. Do you still use the same code for this purpose?
Paolo

I’m guessing that this is to do with the fact that you aren’t using a proper FTDI and that you aren’t getting a proper power/ground supply to the TTL/USB adapter when not powering it from the PC.

However, your screenshot shows a baud rate of 9600 but my code uses 74880 for the serial monitor.

Sometimes. It requires the output of the Tracer to be set to a certain setting, and these aren’t very intuitive.
As you’ll see from my PCB, I’ve started using a 2-way relay board that is connected to D6 and D7, so I mostly use that approach now.

Glad you’ve had some success anyway!

Pete.

It can be, but the GND pin is common for the Wemos, Tracer, and TTL/USB adapter - all of them are interconnected.
Do you think it will work when I will be just sending data to Blynk and ThinkSpeak?

Yes, because the software I was using support communication up to 57600. Of course, to make it work, I reduced the baud rate of the Serial1 in the code to 9600.

So you control the load ON/OFF state via a relay and not by the device itself?
Paolo

Yes, I expect it will.

Either approach works. I have two of these devices, one at home and one in Spain. The one in Spain was running on my original hardware and although I recently upgraded to my new PCB, I’ve not yet swapped over to using the relays to control the load power, as I need to make some changes to my load wiring first.

Pete.

Hello Pete,
Just to let you know - I implemented the ThingSpeak and Blynk with your code and everything is working fine (when connected to an external power source).
When I try to get the Wemos powered directly from PIN 1 (orange) and GND (brown), the board got powered (I can see the onboard LED is on) but it doesn’t really work.
I really don’t understand the reason why it won’t work, I tried to connect directly to VIN and GND and also by attaching the wires to the power inlet jumper - neither way works.

Best regards, Paolo

1 Like

Hi. I have just buy a epever duoracer for my motorhome and it would be amazing if I could monitoring the solar charger from my blynk app with a wemos d1 mini

I will begin to test it.

Regards

I guess that the DuoTracer may use slightly different registers, as presumably it gives different values for each battery.

Pete.

Hello All,
I’m currently working on a project based on tekk and jaminNZx work.
I’ve managed to add quite more functionalities (more data to monitor, esp32 support, how-to guides, …) and I got few more I’d like to implement.
I guess it could be interesting to integrate my solution with yours.

You can take a look to my repository here: Solar-Tracer-Blynk-V3

1 Like

I thought I’d add a little update on what I’m currently doing with my EPEVER solar controllers, and why.
Earlier this year the Tracer controller I have in Spain went faulty and started over-charging my batteries. Instead of the normal bell curve of charging current, which falls off after the battery SOC reaches 100%, the batteries were being charged at full power until the battery or controller temperature hit the preset maximum (around 70°C) then everything would shut down. This quite quickly wrecked the batteries, despite me turning my load on whenever the controller wasn’t shut down due to overheating.
I didn’t have anyone in Spain who could intervene and pull the fuses on the solar panel, so just had to watch the batteries being destroyed from 1000 miles away.
Having an almost identical setup at home in the UK I was able to investigate possible solutions, but unfortunately non of the things I tried were successful.
Instead, I decided to use a different approach for the future, as I realised that if I could run the EPEVER control software on a PC I’d be able to re-configure the controller to turn-off at a lower battery/controller temperature, and possibly reduce the charging cutoff voltage if this type of thing ever happened again.
I decided to try using the Elfin EW-11 module and interrogate it via Node-Red. This worked well, and by installing a virtual serial port driver on a local PC I was also able to run the EPEVER management software as well.
After testing this on my UK setup I recently changed my Spanish setup to use the EW-11 instead of an ESP8266 based system. So far it’s working very well, and uses far less power than my old system, so should help reduce unwanted battery drain during the winter months.

Pete.

Hi @PeteKnight ,

Could you help advise about the configuration using Elfin EW-11 to run the epever management software? Let me know the virtual serial port software that you use as well.

I have Elfin EW-11 as well and already installing a virtual serial port on local PC but can not run epever software.

I was able to run the epever management software so well before using direct serial com to epever rs485 port . but i need communicate to epever software via wifi use EW-11 like your setup.

Thank you.

Hey guys, it’s me (the author of original post).
Just wanted to let you know, that I’ve totally given up using EPever controllers and I’m now using two Victron MPPT 75/15 as it turned out the EPevers are very faulty. (I have 3 faulty EPevers, each with different issue at my shack).
The Victron Energy 75/15 MPPTs have built in Bluetooth which I can use to connect and monitor from the Android phone and it also has a Serial out, for which already exists many integrations on Github (like ESPHome i.e.).
My suggestion is not to buy these controllers, I have bad experience.
Have a nice day everyone!

1 Like

Hi @mrrobot, This is my setup…

I have my EW-11 configured with two comms ports in the Communications Settings tab. The port that’s called “netp” is what I use for the VSP…

The EW-11 serial port settings are configured like this:

I use the HW VSP3 Single driver from here:
https://www.hw-group.com/software/hw-vsp3-virtual-serial-port

and configure it like this:

image

The IP address and port obviously has to match the settings for your EW-11.

The VCP driver creates a tray icon in Windows and this can be used to start/stop and configure the settings (the port has to be stopped (deleted) for settings to be changed). If you check the “Create VSP Port when HW VSP Start-up” option in the Settings tab - and save the settings to the .INI file - then the virtual com port will start automatically when you launch the VSP driver, otherwise you will need to click the Create COM button.

You then have to configure the EPEVER Solar Station Monitor software to use the same com port and baud rate etc, and click the “Start Monitoring” button…

The EW-11 does seem to allow two connections at once, but as I do all of my monitoring via the Node-Red port that I created…


via the ModBus Flex Getter node…

I only tend to use the EPEVER software if I need to change a configuration setting - as mention in an earlier post, and if I was going to do that then I’d probably stop Node-Red polling the EW-11 first, so that I had uninterrupted access to the solar charge monitor via the virtual COM port and the EW-11.

One thing to watch out for is that if you create the VCP on an available COM port on your PC (COM3 in my case) then stop the VCP and plug-in another device which gets assigned as the same COM port number then it will cause problems when you try to fire-up the VCP. If you change the VCP COM port number to get around tis then you also have to change the COM port that’s used in the EPEVER monitoring software.

Pete.

14 posts were split to a new topic: Need help reading data from my inverter (RS232 protocol)