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

Notifications ESP32 & Android

I think we need to see your code (correctly formatted of course).

Pete

Hi Pete, thank you for your fast replie.

I will post the necessary parts of the code because it is a big project and i´m working in Tabs in Arduino IDE.

void Blynk_TimerEvent()
{
  if (pinValueV8 == 1) {
    Blynk.virtualWrite(V16, 1); //Schalter Frostwächter Frischwasser
    //Blynk.notify("Yaaay...Wasserpumpe ist an");
  }
    else {
    Blynk.virtualWrite(V16, 0); //Schalter Frostwächter Frischwasser
    //Blynk.notify("Ohhhh...Wasserpumpe ist ausk");
  }
}

In Setup and Loop Tab there is:

void setup() { 
 Blynk.config(auth, server, port);  // non-blocking, even if no server connection
  Blynk.connect();
  timer.setInterval(1000L, Blynk_TimerEvent);
}
void loop() {
    Blynk.run();
    timer.run();
}

Tab for global things

//Globale Variablen
#define BLYNK_PRINT Serial
// defines pins numbers Ultrasonic
const int trigPin = 23;
const int echoPin = 22;

// defines variables Ultrasonic
long duration;
int distance;



//WiFi reconnect variables
int lastConnectionAttempt = millis();
int connectionDelay = 5000; // try to reconnect every 5 seconds

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
#include "DS3231.h"

char ssid[] = "some";
char pass[] = "hidden";
char auth[] = "stuff";
char server[] = "192.168.50.1";  // IP for your Local Server
int port = 8080;
int measurement = 0;
int pinValueV1;
int pinValueV8;

// This is called when Smartphone App is opened
BLYNK_APP_CONNECTED() {
  Serial.println("App Connected.");
  Blynk.syncAll();
}
// This is called when Smartphone App is closed
BLYNK_APP_DISCONNECTED() {
  Serial.println("App Disconnected.");
}

Adafruit_INA219 ina219;
RTClib RTC;

#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();

BlynkTimer timer;
WidgetRTC rtc;


BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
}

not sure if it is the cause of the issue, but you are sending a virtual write command and a notification every second.

Maybe add a flag so they are only sent if pinValueV8 changes. It may not be such an issue with the virtual write command, but maybe with the notification.

Do you have the disconnection issue with the notification commented out?

Yes you are right, i will add a flag for the notification. I have no issues when commenting out the notification.

Edit: I didn´t added a flag. I changed the code and added it in my write Tab so it will do it only if i change the state of the button.

// This function will be called every time a Widget or Button
// in Blynk app writes values to the Virtual Pin
BLYNK_WRITE(V1)
{
  pinValueV1 = param.asInt(); // assigning incoming value from pin V1 to a variable

  // process received value
}
BLYNK_WRITE(V8)
{
  pinValueV8 = param.asInt(); // assigning incoming value from pin V8 to a variable

  // process received value

    if (pinValueV8 == 1) {
    Blynk.virtualWrite(V16, 1); //Schalter Frostwächter Frischwasser
    Blynk.notify("Yaaay...Wasserpumpe ist an");
  }
    else {
    Blynk.virtualWrite(V16, 0); //Schalter Frostwächter Frischwasser
    Blynk.notify("Ohhhh...Wasserpumpe ist aus");
  }
}

Same issue

Have you checked your server logs?
Messaging uses the GCM - http.googleapis.com service. If you see any log entries about this then that will be a clue about your issue.

Pete.

My logs seems crazy. With ls -l in home/Blynk/logs the changedate of the logfile is one month ago? In these logfiles are no entrys with GCM. Are these the correct logfiles?

In logs is blynk.log, postgres.log, stats.log, worker.log

More info here:

Pete.

Very strange things happen. In my Server.properties i changed log Level to debug but there are no new logs created. I also tried different log Locations. Also my attached RTC to the Pi had a time drift this morning for about 3hours. Now the RTC is still available with i2detect but i cant read or write the time anymore.

I will Setup the Pi new this Weekend and i will inform you of the result when i finished. Hopefully the notifications will work then.

I tried alot in the past but didn´t managed it. I think notifications won´t work on local server without internet connection or?

Also i found out that there will be no log files created when i start the server automatically on reboot with following entry in /etc/rc.local:

java -jar /home/pi/Blynk/server-0.41.11-java8.jar -dataFolder /home/pi/Blynk -serverConfig /home/pi/Blynk/server.properties -mailConfig /home/pi/Blynk/mail.properties &

Logfile blynk.log:

01:08:41.405 INFO - Using data dir '/home/pi/Blynk'
01:08:41.911 DEBUG- Starting reading user DB.
01:08:49.293 DEBUG- Reading user DB finished.
01:08:49.296 INFO - Region : local. Host : 192.168.50.1.
01:08:54.697 INFO - Initializing gmail smtp mail transport. Username : infinity1704@gmail.com. SMTP host : smtp.gmail.com:587
01:08:55.045 INFO - Reports : 0
01:08:55.084 INFO - Didn't find Let's Encrypt certificates.
01:08:55.086 WARN - You didn't specified 'server.host' or 'contact.email' properties in server.properties file. Automatic certificate generation is turned off. Please specify above properties for automatic certificates retrieval.
01:08:55.088 WARN - ATTENTION. Server certificate paths (cert : '/home/pi/./server.crt', key : '/home/pi/./server.pem') not valid. Using embedded server certs and one way ssl. This is not secure. Please replace it with your own certs.
01:09:28.928 DEBUG- hard.socket.idle.timeout = 10
01:09:29.531 INFO - HTTP API and WebSockets server listening at 8080 port.
01:09:29.545 INFO - HTTPS API, WebSockets and Admin page server listening at 9443 port.
01:09:29.550 INFO - Mqtt hardware server listening at 8440 port.
01:09:32.393 DEBUG- completeLogin. [id: 0x9d025e49, L:/192.168.50.1:8080 - R:/192.168.50.71:63069]
01:09:32.484 INFO - infinity1704@blynk.cc hardware joined.
01:09:33.176 DEBUG- Re registering app channel. [id: 0xde0f5608, L:/192.168.50.1:9443 - R:/192.168.50.2:57602]
01:09:33.244 INFO - infinity1704@blynk.cc Blynk-app (android-22710) joined.
01:09:35.737 DEBUG- Aborting Future NettyResponseFuture{currentRetry=0,
	isDone=0,
	isCancelled=0,
	asyncHandler=cc.blynk.server.notifications.push.GCMWrapper$1@1674c6d,
	nettyRequest=org.asynchttpclient.netty.request.NettyRequest@1857fde,
	future=java.util.concurrent.CompletableFuture@8bcfea[Not completed],
	uri=https://fcm.googleapis.com/fcm/send,
	keepAlive=true,
	redirectCount=0,
	timeoutsHolder=org.asynchttpclient.netty.timeout.TimeoutsHolder@17f8c1f,
	inAuth=0,
	touch=575679}

01:09:35.738 DEBUG- fcm.googleapis.com: unknown error
java.net.UnknownHostException: fcm.googleapis.com: unknown error
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[?:1.8.0_65]
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[?:1.8.0_65]
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[?:1.8.0_65]
	at java.net.InetAddress.getAllByName0(InetAddress.java:1276) ~[?:1.8.0_65]
	at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_65]
	at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_65]
	at io.netty.util.internal.SocketUtils$9.run(SocketUtils.java:159) ~[server-0.41.11-java8.jar:?]
	at io.netty.util.internal.SocketUtils$9.run(SocketUtils.java:156) ~[server-0.41.11-java8.jar:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_65]
	at io.netty.util.internal.SocketUtils.allAddressesByName(SocketUtils.java:156) ~[server-0.41.11-java8.jar:?]
	at io.netty.resolver.DefaultNameResolver.doResolveAll(DefaultNameResolver.java:52) ~[server-0.41.11-java8.jar:?]
	at io.netty.resolver.SimpleNameResolver.resolveAll(SimpleNameResolver.java:81) ~[server-0.41.11-java8.jar:?]
	at io.netty.resolver.SimpleNameResolver.resolveAll(SimpleNameResolver.java:73) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.resolver.RequestHostnameResolver.resolve(RequestHostnameResolver.java:50) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.netty.request.NettyRequestSender.resolveAddresses(NettyRequestSender.java:357) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.netty.request.NettyRequestSender.sendRequestWithNewChannel(NettyRequestSender.java:300) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.netty.request.NettyRequestSender.sendRequestWithCertainForceConnect(NettyRequestSender.java:142) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.netty.request.NettyRequestSender.sendRequest(NettyRequestSender.java:113) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.DefaultAsyncHttpClient.execute(DefaultAsyncHttpClient.java:241) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.DefaultAsyncHttpClient.executeRequest(DefaultAsyncHttpClient.java:210) ~[server-0.41.11-java8.jar:?]
	at org.asynchttpclient.BoundRequestBuilder.execute(BoundRequestBuilder.java:35) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.notifications.push.GCMWrapper.send(GCMWrapper.java:75) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.core.model.widgets.notifications.Notification.push(Notification.java:53) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.hardware.handlers.hardware.logic.PushLogic.messageReceived(PushLogic.java:75) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.hardware.handlers.hardware.HardwareHandler.messageReceived(HardwareHandler.java:85) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.hardware.handlers.hardware.HardwareHandler.messageReceived(HardwareHandler.java:43) ~[server-0.41.11-java8.jar:?]
	at cc.blynk.server.common.BaseSimpleChannelInboundHandler.channelRead(BaseSimpleChannelInboundHandler.java:43) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) ~[server-0.41.11-java8.jar:?]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) ~[server-0.41.11-java8.jar:?]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) ~[server-0.41.11-java8.jar:?]
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) ~[server-0.41.11-java8.jar:?]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) ~[server-0.41.11-java8.jar:?]
	at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) ~[server-0.41.11-java8.jar:?]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[server-0.41.11-java8.jar:?]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[server-0.41.11-java8.jar:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
01:09:35.741 ERROR- Error sending push. Reason fcm.googleapis.com: unknown error
01:09:36.649 DEBUG- Re registering app channel. [id: 0x69886736, L:/192.168.50.1:9443 - R:/192.168.50.2:57604]
01:09:36.659 INFO - infinity1704@blynk.cc Blynk-app (android-22710) joined.

Correct.

Pete.

But only push notifications can’t be done without Internet connection.

According to following site, notifications should be possible: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Blynk uses the GCM service for the notification widget, both on Android and iOS. GCM requires internet access for it to work.

Pete.

This information should be added to the blynk docs. Not everybody is confirm with the Google Cloud Messaging or knows how push notifications works in general.

Maybe Blynk is able to use normal notifications in the future?! Is it possible to generate a request?

Blynk is an IoT system, and as such it expected that it will be connected to the Internet.
Yes, some people use a local server in a closed environment, but in that situation it should be expected that some functionality will dork differently, or not at all.

I don’t think that there is a messaging system that will work with both Android and iOS which will meet your needs, but if you are aware of one then you could submit your idea here:

You should be aware that the developers are currently working hard on Blynk V2, and (at least in the initial release) this will be 100% cloud based. The option to install a local server version may follow later (or not).

Pete.

I have the same problem on my own blynk server. It is connected to internet and everything works just fine except for the notifications. If i send a notification [Blynk.notify(“TEST”);] i don’t receive anything on my pixel 4a Android phone.
The Blynk version is v0.41.16.
Any ideas?
Thanks in advance

What Blynk library version are you using?

Pete.

1.0.0.0 beta3 I can give the released version 0.6.1 a try?

Notifications don’t work with the 1.0.0-Beta-x versions of the library. You should be using 0.6.1

Pete.

Thank you very much!
That was the problem. I changed to 0.6.1 and it is working now…
Should have posted this earlier, spend a lot of time trying to fix this. :see_no_evil:
Is that documented? I could not find anything about that on the internet.

Covered many times, you just need to do a quick search…

Pete.

1 Like