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

Connection through SIM7020E and NB-IOT

Hi there,

The root purpose of my project is to transfer data to Blynk using a modem SIM7020E and NB-IOT network.
Therefore I adapted the fantastic TinyGSM library to working with modem SIM7020E and features TCP App, TLS …

But i have facing a strange Blynk behavior using TLS connection to blynk-cloud.com:443.
Connection is success but app receiving from server reconnect message (29000100113133392E35392E3230362E313333003830 = BlynkCmd 41, 139.59.206.133:80)
After that TLS connection cannot establish because port 80 is assigned instead of 443.

Why server trying to redirect client to unsecured connection? Could this be related with high latencies and low speed in NB-IOT networks?

As a work around can use connection to 139.59.206.133:443 instead of blynk-cloud.com:443, in this case, the redirect does not occur

I have read a little blynk-local’s code and now understand why it happens

protected void channelRead0(ChannelHandlerContext ctx, LoginMessage message) {
        String token = message.body.trim();
        TokenValue tokenValue = holder.tokenManager.getTokenValueByToken(token);

        if (tokenValue == null) {
            //token should always be 32 chars and shouldn't contain invalid nil char
            if (token.length() != 32 || token.contains(StringUtils.BODY_SEPARATOR_STRING)) {
                log.debug("HardwareLogic token is invalid. Token '{}', '{}'", token, ctx.channel().remoteAddress());
                ctx.writeAndFlush(invalidToken(message.id), ctx.voidPromise());
            } else {
                //no user on current server, trying to find server that user belongs to.
                checkTokenOnOtherServer(ctx, token, message.id);
            }
            return;
        }

NB-IOT modem and WiFi network that was used to register the token has a different DNS response

WiFi:

nslookup blynk-cloud.com

╚ь : blynk-cloud.com
Address: 139.59.206.133

NB-IOT modem:

OK
AT+CDNSGIP=“blynk-cloud.com
OK

+CDNSGIP: 1,“blynk-cloud.com”,“45.55.96.146”

There are three Blynk cloud servers (as far as I know) and a project and its associated auth code can only exist on one of these servers.

139.59.206.133 is the Europe server and 45.55.96.146 is the Asia server.

Normally, if you’re in a location where the app or device tries to connect to the local server but that’s not the one where your project lives then it does some clever redirection in the background, but that’s not working for you.

I guess that leaving the IP address hard-coded is the simplest solution, as this is what needs to happen for services such as IFTTT, so the IP address inst likely to change any time soon.

Pete.