Victron BMV 700 - WEMOS D1 Mini

Hi
This is my first post on this forum so firstly, Hi to everyone.
I’m a total noob with any code so anything I’ve learned so far is thanks to you guys.

I would like to interface a Victron BMV 700 battery monitor with my Wemos D1 Mini and deliver the output to my iPhone using Blynk.

So far I’ve tried a few examples of others which have written code to successfully talk to the Victron BMV 700 but I can’t see anything so far that interfaces with Blynk.

Any ideas gratefully received.

A quick search reveals that

“There are two ways of communicating. One is the text protocol. The Victron spews out plain text every second… The second is their Hex Protocol which allows a conversation and sending commands

http://caravanersforum.com/viewtopic.php?t=63614

Timing can be an issue when using Blynk, as the Blynk background processes demand processor time on a frequent basis, and waiting for data to be “spewed out” then processing that data could cause some Blynk timing issues.

Better to take the approach that the author of the article did, and make this a triggered conversation at a frequency of your choice. However, the code to do this can’t be in the void loop as in the example code. It must be in a separate function that you call with a Blynk timer. The same function can be used to process the results and write them to Blynk. Take care not to call the function too often - probably every 5 seconds will be more than enough.

The author of the article used an Arduino, which uses 5v logic levels, so he needed a level shifter to conver to the 3.3v used by the device. Your Wemos uses 3.3v logic levels, so you don’t need to worry about level shifting.

I’d start by getting his code (or another example that uses the same data polling principal) running without Blynk, then modifying it to be Blynk friendly by cleaning-up the void loop with a Blynk timer.

When this is working, add-in the Blynk connection code and some virtual write commands to push the data to Blynk.

It will be difficult for others to help you, unless you find someone already using the same hardware, but we’ll try to point you in the right direction if we can.

Pete.

hey!

did you managed to send the data to blynk from the victron? i have a blue solar mppt controller, and i face the same problem.

however, i use this library, which is quite different for the approach in the http://caravanersforum.com link…

so far, i can receive the serial data from the controller, but when i try to integrate with blynk, it crashes the esp :frowning: no matter how i try…

i guess that the serial read is not compatible with the blynk protocol.

Hi

Thanks for the prompt reply, I understand there aren’t going to be many people trying to achieve the same thing so I know I’ll never get an off the shelf sketch that will do what I need.

Your reply has been more helpful than you can imagine, firstly its confirmed the 3.3v logic doesn’t require any further hardware conversion, I was wondering if that was what was stopping any serial responses.

I’d already found the link you posted and it quickly went over my head. Now I’m a bit more confident that my hardware will work I’ll go and learn some more about the caravaners software.

Hi

Yes I’ve got the code working for the BMV-600 battery monitor so I’m sure a similar code would work for the solar controllers.
I’m running this on a boat and it 100% works great, I can see all the info I need on my phone in realtime via the Blynk app.
It’s not 100% reliable, seems to run for about 3 days then crash but I think this is due to very short internet connectivity issues.
I never notice the internet go down but there could easily be tiny interruptions that trip up the blynk code or something.

There is some code available to keep checking the internet connection then reboot if no connection is detected so I really should add this but I’ve not had the time or enthusiasm yet.

I’ll try to find the working version of my code and share it when I work out how to do this.

Julian

1 Like

thanks for the info!

i would be really curious about your code…
did you manged to put it together, or someone helped?

since yesterday, i’ve done more research, and figured out why my sketch is crashing with blynk:

unfortunately, there is a serious issue with the esp core softwareserial implementation. since core 2.4.0 softwareserial causes data loss and crashes when used together with wifi :frowning:

if you google softwareserial + esp8266 + crash, you will see that lots of other people have this problem. the most recent thread i’ve found is this (but there are lots of others too):

so, i’m pretty sure my code should work, if this issue would be solved. now i wonder if i could use the hardware serial, but that would cause other disatvantages…

You could use Serial1 for your debug monitor (it’s Tx only, but that’s fine for debug serial and would need an FTDI adapter) the use the regular Serial UART for 2-way comms with the controller.

Interesting about the ESP core issue with SoftwareSerial, I hadn’t heard of that before.

Pete.

probably will try that.

at the beginning, i do not need 2-way comm on the mppt either, i just listen on the tx port and receive the data. at the moment, i just use 2 wires, gnd and tx on the mppt.

the esp softwareserial issue is interesting and rather sad, especially that they didn’t solved for more than one year… apparently also the implementation in the arduino is not so stable:

"That SoftwareSerial implementation is done as bad as the one available for the Arduino platform. It waits with empty loops during the transfer (receiving or sending) of a complete byte. In the reception case this is even done in interrupt context, so other interrupts are blocked.

So I give you the same advice I give for Arduino users: don’t use SoftwareSerial if you plan to do other stuff (WiFi is just one example) on that processor at the same time as the serial transfer takes place."

1 Like

Hi

I’ve just re-checked my original code thats running on my BMV Monitor and it does use software serial so this could well be a cause of my intermittent crashes.

I’m happy to share my code but I’m not sure how to do this here, obviously I don’t want to share my auth code and wifi details, do I just post it as text and edit out those details?

Yes just replace with xxx’s or something of that nature.

Also make sure to add three backticks ``` (not apostrophes or single quotes) before and after your code, if not it may be removed :wink:

Ok

Here is the code I’m currently using, I’m really not a coder so I expect the parts I have done is awful and full of bugs.
I can’t take credit for much at all of this, most of it was from the caravaners forum by an Australian chap, his code was great but I expect in cutting it back to make it do what I wanted I’ve most likely discredited his original achievement which did way more than I needed.

However it does work perfectly but only seems to run for a few days before crashing.
Mine also supports the DHT22 temp/hum sensor which seems to be wildly inaccurate too.
I’d be really grateful if anyone could tell me why it only runs for a few days so we could improve it.

#include <SoftwareSerial.h>
#include <SPI.h>
#define BLYNK_PRINT Serial //Jue
#include <ESP8266WiFi.h> //Jue
#include <BlynkSimpleEsp8266.h> //Jue
#include "DHTesp.h"
DHTesp dht;
BlynkTimer timer;

char auth[] = ""; //Jue
char ssid[] = ""; //Jue
char pass[] = ""; //Jue
 
SoftwareSerial Victron(D7,D8); // RX, TX //Jue changed this

 
char p_buffer[80];
#define P(str) (strcpy_P(p_buffer, PSTR(str)), p_buffer)
 
char c;
String V_buffer;  // Buffer to hold data from the Victron monitor
 
float Current;
float Voltage;
float SOC;
float CE;

String stringOne;
 
void setup()
{
 
  Serial.begin(19200);
  Victron.begin(19200);
  Blynk.begin(auth, ssid, pass); //Jue
  dht.setup(D4, DHTesp::DHT22);
  timer.setInterval(5000, sendDatatoBlynk);
}

void sendDatatoBlynk() {
  // These if statements make sure only to send data if data has been set in the main loop already

  Serial.println("I am called within sendDatatoBlynk function");

   float h = dht.getHumidity();
    float t = dht.getTemperature();
 
   
    Blynk.virtualWrite (V5,h);
    Blynk.virtualWrite (V6,t); 
  
  if(Current){
    Blynk.virtualWrite (V2,Current);
      
  }

  if(Voltage){
    Blynk.virtualWrite (V1,Voltage);
    
  }

  if(SOC){
    Blynk.virtualWrite (V4,SOC);
    
  }

  if(CE){
    Blynk.virtualWrite (V3,CE);
    
  }
}
 
void loop() {

  Blynk.run(); //Jue
  

  // Victron 
 
  if (Victron.available()) {
    c = Victron.read();
 
    if (V_buffer.length() <80) {
      V_buffer += c;
    }
 
    if (c == '\n') {  // New line.
 
      if (V_buffer.startsWith("I")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        Current = (float) temp_int/1000;
        
      }     
 
      if (V_buffer.startsWith("V")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        Voltage = (float) temp_int/1000; 
        
        
      }     
 
      if (V_buffer.startsWith("SOC")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        SOC = (float) temp_int/10;
        
        
      }
      if (V_buffer.startsWith("CE")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        CE = (float) temp_int/1000;
        
        }

      timer.run();
      V_buffer=""; // Empty V_Buffer
      
    }
    }
    }

Julian.

1 Like

You need to get all the other code regarding reading the serial out of void loop and into a timer.

Your void loop() wants to look like this:

void loop() {
  Blynk.run();
  timer.run();
}
1 Like

You seem to have taken the opposite approach to the example in the caravan link.
You seem to be waiting for data to be pushed out, rather than instigating a read on a regular basis.

Pete.

Ah, I looked at so many examples during development its likely I mixed up the sources.

Apologies for that.

Sounds great but I have no idea how to do this.

If you re-read what I said in the second post in this thread, you may see why you’re getting disconnections…

Waiting for an output from the device will cause issues, whether you put that in the void loop or in a separate timed function. Much better to call a function which queries the device.
Read the examples in the “keep your void loop clean” article and you’ll see how to do this.

Pete.

2 Likes

thanks a lot!

i’m a bit busy these days, but will take a look as soon as i can, and will try to optimise your code.

maybe you can tell me what esp core version are
you using?

when this happens, you have to reset the esp manually, or it restarts by itself?

arr you sure you do not have the blue one (dht11)? those are known for bad quality, but the white ones should be quite ok.

if you need more accuracy, you can try a bme280, they are among the best sensors, and it also has a barometer function.

https://m.aliexpress.com/item/32659765502.html?trace=wwwdetail2mobilesitedetail&productId=32659765502&productSubject=BME280-Digital-Sensor-Temperature-Humidity-Barometric-Pressure-Sensor-New&ws_ab_test=searchweb201556_0,searchweb201602_1_10037_10017_10034_10021_507_10022_10032_10020_10018_10019,searchweb201603_6&btsid=da491996-c712-4842-a19a-9bb10914d66d

1 Like

As you can probably tell I haven’t touched any of this hardware or software for some time.
Once this was running in its basic form I’m afraid I lost interest a bit but thankfully now I’m chatting on here again I might find the enthusiasm to work on it some more.
I’d really like to get it to a commercial product that I could sell with my boat solar installations.

My current core version is 1.8.8 if thats the one you mean.
The sensor I have is the white one but it does seem to read higher than the actual temperature, for example the sensor says 25.5c right now and my indoor thermometer says 22.5c, having said that the sensor is the piggy back board version and it is in a cupboard so it could actually be warmer there and also I read they pick up heat from the main circuit board.
I do have a BME280 but from memory I had hassle with the libraries for it.

I can’t actually tell what happens when my system crashes, I think the code is still running but I think its disconnecting from the internet, Blynk says its gone offline which could mean either really.
It never recovers on its own and does require a reset button.
I should really ping it next time it crashes.

Hmm

None of my sketches will compile now, error says esp8266wifi.h not found.

In that case you should start talking to the guys at Blynk.io as you’ll need to sign-up to a commercial licence to do that. As you’re struggling with your development they will help with this and get your project to a point where it’s doing what you want.

The ESP core will have a version number in the 2.x.x or 3.x.x range. Check by going to boards manager in the Arduino IDE and scrolling down to the bottom of the list. 2.4.2 is the version that I’d Reccomemd, anything in the 3.x.x range is too buggy to use.

Any sensor located near your board will read incorrectly because f the heat generated by the board…
The BME280 is a great sensor and very easy to use. I’d recommend it over any of the DHT sensors.

Pete.