How to reduce blynk library size?

hello!

currently i’m working on a remote weather station project. in my sketch i need to use a lots of sensors, so i have to include several arduino libraries.

when i also include blynk + enc28j60 stuff, the sketch grows way bigger (140%) than the atmel328p footprint. (without blynk + uipethernet the sketch uses just ~50%)

i know, the easiest solution would be, to go with a larger mcu, but this is an existing hardware, with a custom made circuit, using the atmel328p. to upgrade the mcu, i would have to re-design the whole pcb + circuit + case, it is not possible right now.

there is a way to reduce the size of the blynk library? i need just one way communication (station -> blynk server). just sending the sensor values to the server.

or, it would be better to use just the uipethernet lib, and send the values with http api commands, implemented in the sketch? like this: “http://blynk-cloud.com/9b83187bd48e459f84/update/V3?value=100

thanks!

this will probably gives you the smallest sketch size but I can’t say I have tested it as I have 1MB of programmable memory on my “Arduino clone with WiFi” (aka ESP) plus a further 15MB of data sorage.

can someone please help? i try to send value via blynk API, but it is not working…

this is my code, based on this and this:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char serverName[] = "www.blynk-cloud.com";

EthernetClient client;

void setup()
{
  Serial.begin(115200);

  if (Ethernet.begin(mac) == 0) {
    Serial.println("failed to configure ethernet using DHCP");
  }

  delay(1000);
  Serial.println("connecting...");

  if (client.connect(serverName, 80)) {                        // starts client connection
    Serial.println("connected");

    // Make a HTTP request:
    client.print("GET /xxxxxxxxxxxxxxxxxxxxxxxxxxxx/update/V3?value=100");
    client.println(" HTTP/1.1");
    client.println("Host: www.blynk-cloud.com");
    client.println("Connection: close");
    client.println();                                          // end of get request
  }
  else {
    Serial.println("connection failed");
  }

  while (client.connected() && !client.available()) delay(1);  // waits for data

  while (client.connected() || client.available()) {           // connected or data available
    char c = client.read();                                    // gets byte from ethernet buffer
    Serial.print(c);
  }

  client.stop();
  Serial.println("connection closed");
}

void loop() {}

after runing this code, i receive on serial monitor:

connecting…
connected
connection closed

…but the values are not updated in the blynk app.

however, if i simply paste: blynk-cloud.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/update/V3?value=100 in my browser, it refreshes the value instantly.

Should be blynk-cloud.com

There are 2 Blynk examples for writing to pins via API in the Arduino IDE. One is ESP and the other is Ethernet.

They both use PUT not GET, perhaps take a look at them.

Blynk Github and latest version of library in the Arduino IDE is the best place for up to date. working examples.

i’ve already tried with blynk-cloud.com, but could not connect:
connecting…
connection failed
connection closed

thanks, i’m checking out right now!

it is working with the “put” example. i will use this in my code.
thanks @Costas!

You can also take a look at Arduino Blynk library static memory footprint report
There are some hints how to reduce footprint.

nice article, thanks!
as i can see, the problem is, that the ethernet libs consuming a lot of space.

if i upload the basic blynk ethernet example to my uno, with debug and serial disabled, it says:

Sketch uses 15,914 bytes (49%) of program storage space. Maximum is 32,256 bytes.
Global variables use 480 bytes (23%) of dynamic memory, leaving 1,568 bytes for local variables. Maximum is 2,048 bytes.

this sketch is basically doing nothing, just needed for communication. if i add just a bme280 sensor library, i’m out of space…

For sensor-cloud only, HTTP API can be better…
You need to check

ha! the uipethernet lib is even much worser than the standard ethernet…
this sketch is insane :slight_smile:

#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>

char auth[] = "YourAuthToken";

void setup()
{
  Blynk.begin(auth);
}

void loop()
{
  Blynk.run();
}

Sketch uses 24,298 bytes (75%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,343 bytes (65%) of dynamic memory, leaving 705 bytes for local variables. Maximum is 2,048 bytes.

Yes, but this library alone is big - it’s not Blynk’s fault :wink:
As I said, you can make Blynk very small - it runs even on ATTint85!
You can enable all those defines, and remove debug prints.

don’t get me wrong. after reading your article, it is clear to me that not blynk’s fault!

currently i’m trying to reduce the uipethernet lib size. unfortunately, in the hardware i’m working with, is incorporated the enc28j60, so i can not use other ethernet module… i must reduce somehow the library size.

1 Like

You may be able to cut out the UDP parts and maybe even DNS by using IP numbers. That should save some space and technically it’s not needed for TCP to function. You could eliminate DHCP by providing static addresses. That may help too.

-edit

Some more info here: https://github.com/ntruchsess/arduino_uip/issues/74

1 Like

this is exactly what i try to do now, based on the link you posted, + this: https://github.com/ntruchsess/arduino_uip/issues/89

interestingly, if i use "blynk-cloud.com" it can not connect, but if i use IPAddress server_ip (46, 101, 143, 225); it works.

finally, these are the modifications, if anyone interested.
in blynk:

#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations

byte arduino_mac[] = { 0xDE, 0xDD, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress server_ip (46, 101, 143, 225);
IPAddress arduino_ip ( 192,   168,   0,  133);
IPAddress dns_ip     ( 192,   168,   0,   1);
IPAddress gateway_ip ( 192,   168,   0,   1);
IPAddress subnet_mask (255, 255, 255,   0);

Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

…and in uipethernet-conf.h:

#define UIP_CONF_MAX_CONNECTIONS 1
#define UIP_CONF_UDP             0
#define UIP_CLIENT_TIMER        -1

using these settings saved 23% space! even remains a little extra:
Sketch uses 30,578 bytes (94%) of program storage space.
Global variables use 1,122 bytes (54%) of dynamic memory.

comparing, without modifications:
Sketch uses 37,768 bytes (117%) of program storage space.
Global variables use 1,397 bytes (68%) of dynamic memory.

thank you, blynk community, for the great support! :slight_smile:

1 Like

Always good to have real music fans among us :wink:

And yr welcome. You may want to switch to Wemos boards if you feel like you need more space for stuff. Only thing is, they cannot be connected via Ethernet, well, I’m trying now, so far no succes, but they tend to behave pretty good on wifi :slight_smile:

thanks!
regarding music, i know its not relevant to this topic, but you can take a look here. it is an older project, but it still works great, i use it every day.

somewhat off topic but a few things to look at:

from Ethernet cable connection to ESP8266 w/ or w/o RJ45 jack - Everything ESP8266 and ESPthernet by cnlohr at Ethernet Controller Discovered In The ESP8266 | Hackaday (NOT on April’s Fool joke).

Just something I found this morning and I have no idea if either solutions are suitable.
Let us know if you get up and running.

It appears to work with the BlynkSimpleEthernet Sketch, but not with the BlynkSimpleUIPEthernet example and I’m not sure of the SImpleEthernet will work with the ENC board. I have to try that, but won’t be able to do that the coming few days I think, not sure, but I’ll try and report back.