BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Victron BMV 700 - WEMOS D1 Mini

esp8266
#4

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.

0 Likes

#5

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

#6

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…

0 Likes

#7

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.

0 Likes

#8

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:

https://forum.arduino.cc/index.php?topic=451710.0

"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

#9

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?

0 Likes

#10

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:

0 Likes

#11

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

#12

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

#13

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.

0 Likes

#14

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

Apologies for that.

0 Likes

#15

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

0 Likes

#16

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

#17

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.

1 Like

#18

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.

0 Likes

#19

Hmm

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

0 Likes

#20

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.

0 Likes

#21

Ok, I’ve spent some time re-learning some of this stuff and ended up reinstalling the whole software suite before I could managed to compile my original code.

So now I’ve got Arduino V1.8.9, ESP Core 2.5.2 & Blynk 0.6.1
I haven’t had time to upload anything new to my Wemos board and with that core number I’m sure it probably wouldn’t work anyway, I think the previous core version was 2.3.0 but I might just try it before downgrading back to 2.3.0.

I’ve got another board at my office and a BME280 so maybe I’ll recompile with that one to save breaking my operational board which is ok other than it crashes every few days.

The chap that was previously helping me did create another version of the code with the additional parts to check for internet connection and reboot if not available, I never tested this and it does not have the code for the temp sensor but I’ll post it here in case its any use.

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

char auth[] = ""; //Jue
char ssid[] = ""; //Jue
char pass[] = ""; //Jue
 
SoftwareSerial Victron(D7,D8); // RX, TX //Jue changed this
WidgetLED led1(V6);
 
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()
{
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.begin(19200);
  Victron.begin(19200);
  Blynk.begin(auth, ssid, pass); //Jue
  readVictronData(); // This will initially set Victron variables 
  timer.setInterval(5000, sendDatatoBlynk); // Send Data to blynk every 5 sec
}

// Main void loop that will continously be running
void loop() { 
  if (WiFi.status() != WL_CONNECTED) { // If wifi is not connected run reconnect() function
    reconnect();
  }

  if (Blynk.connected()) {  // Checking Blynk connection. If connected...
    led1.on();          // Turn on Virtual LED in app
    Blynk.run();        // Run Blynk
    readVictronData();  // Read Victron Data
    timer.run();        // Will make sure sendDatatoBlynk is called
   } else {
    Serial.println("Whoops blynk is not connected need to do something about that");
    led1.off();             // Turn of LED in app if connection to blynk is down
    CheckBlynkConnection(); // If Blynk connection is down, this will be called, should reconnect
   } 
  }

void reconnect() {
  Serial.print("Reconnecting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");  // As long as it is trying to connect print a . each 500ms to debugger
  }
  Serial.println("");
  Serial.println("WiFi re-connected");
  
}

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");
  
  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 readVictronData() {
  if (Victron.available()) {
    c = Victron.read();
 
    if (V_buffer.length() <32) {
      V_buffer += c;
    }
 
    if (c == '\n') {  // New line.
 
      if (V_buffer.startsWith("I")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        double 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;
       
      }
  
     
      V_buffer=""; // Empty V_Buffer
    }
  } else {  // If Victron not available reset software
    Serial.println("Reset..");
    ESP.restart();
  }
}

void CheckBlynkConnection(){    // check if connected to Blynk server
  if(!Blynk.connected()){
    Serial.println("Not connected to Blynk server"); 
    Blynk.connect();  // try to connect to server with default timeout
  }
  else{
    Serial.println("Connected to Blynk server");     
  }
}
0 Likes

#22

At least the Void Loop is a little bit tidier in this one.

0 Likes

#23

Not much point in using WiFi.begin then Blynk.begin.
It would make more sense to use WiFi.begin, Blynk.config then Blynk.connect.

Pete.

1 Like