After the device (NodeMCU) connects to wifi, obtains a local IP address (from the Smartphone tethered wifi DHCP), connects to the mobile ISP DNS and obtains the blynk-cloud IP address, attempts to connect to blynk-cloud and sends my Auth Token, the blynk client reports time-out, and never gets the “>[00|00|01|00|C8]” messages from Blynk-cloud.
Background:
I purchased a low-cost cellphone (MobiWire Sakari) which I want to use as my IOT device’s internet connection to Blynk-Cloud (instead of say, SIM900 etc). The cellphone has wifi-tethering and I requested an unrestricted APN on the SIM from the Cellular provider. I loaded data time, and was able to browse from the smartphone OK. Next I tested the tethering by connecting to the smartphone from my PC WIFI dongle, all good with internet browsing etc. Next I tried accessing my Blynk-cloud project from the PC tethered to the smartphone, it works OK with MS explorer and telnet and returns the correct HTML/Json script information for my project on blynk-cloud.
However, when I tried the Blynk ESP8266 example sketch on an NodeMCU via the tethered smartphone, the connection stalls and times out after the DNS look-up of Blynk-Cloud.com and the initial IP connection attempt and just after my Blynk example sketch debug shows sending the Auth Token. The next thing that happens is that the device attempts to connect again by doing the DNS lookup again, so it seems like my device is not getting authenticated by the Blynk-cloud server at 45.55.96.146 or the latency is too high
If I try connecting via my home Broadband WIFI router it works perfectly.
I loaded an ESP8266/Arduino HTTP client example sketch from my Arduino IDE to the NodeMCU and it works perfectly to blynk-cloud via the tethered smartphone.
I tried increasing the network timeout time (>6000mS!) in the Blynkconfig.h with no luck.
I tried using LWIP 1.4, no luck.
I tried ports 80 and 8080, no luck.
All my other IOT projects (MQTT etc) seem to be connecting OK through the tethered smartphone.
I tried a different smartphone using the same SIM, same result.
At first I thought it may be an issue with my mobile data provider blocking ports, however it is working when I use a PC internet browser and I have tested using both 80 and 8080 ports using http://portquiz.net/
I am unable to wireshark the link so I have just made serial output dumps for debugging.
Platform:
NodeMCU 0,9. (ESP-12e)
Arduino core: SDK:3.0.0-dev(c0f7b44)/Core:2.5.0=20500000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1/BearSSL:6778687
Blynk Library 0.5.4
ESP8266: ESP ardjuino communitity core - 2.5.0 (non Git version)
IDE: Arduino/Windows 64 1.8.5
LWIP: V2 Lower Memory.
Blynk Sketch:
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You’ll need:
- Blynk App (download from AppStore or Google Play)
- ESP8266 board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial // Defines the object that is used for printing these have to be here not lower in the code
#define BLYNK_DEBUG // Optional, this enables more detailed prints
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c2700ca3f8fa4bb9b03d8d6c778a8f40";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Grace 3G";
char pass[] = "11111111";
//char ssid[] = "Love";
//char pass[] = "A850F3619D";
void setup()
{
// Debug console
Serial.begin(9600);
//Blynk.begin(auth, ssid, pass);
// You can also specify server:
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
Library used:
/**
* @file BlynkConfig.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Configuration of different aspects of library
*
*/
#ifndef BlynkConfig_h
#define BlynkConfig_h
#include <Blynk/BlynkDetectDevice.h>
/***************************************************
* Change these settings to match your need
***************************************************/
#define BLYNK_DEFAULT_DOMAIN "blynk-cloud.com"
#define BLYNK_DEFAULT_PORT 80
#define BLYNK_DEFAULT_PORT_SSL 8441
/***************************************************
* Professional settings
***************************************************/
// Library version.
#define BLYNK_VERSION "0.5.4"
// Heartbeat period in seconds.
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT 30
#endif
// Network timeout in milliseconds.
#ifndef BLYNK_TIMEOUT_MS
#define BLYNK_TIMEOUT_MS 6000UL
#endif
// Limit the amount of outgoing commands per second.
#ifndef BLYNK_MSG_LIMIT
#define BLYNK_MSG_LIMIT 15
#endif
// Limit the incoming command length.
#ifndef BLYNK_MAX_READBYTES
#define BLYNK_MAX_READBYTES 256
#endif
// Limit the outgoing command length.
#ifndef BLYNK_MAX_SENDBYTES
#define BLYNK_MAX_SENDBYTES 128
#endif
// Uncomment to use Let's Encrypt Root CA
//#define BLYNK_SSL_USE_LETSENCRYPT
// Uncomment to disable built-in analog and digital operations.
//#define BLYNK_NO_BUILTIN
// Uncomment to disable providing info about device to the server.
//#define BLYNK_NO_INFO
// Uncomment to enable debug prints.
//#define BLYNK_DEBUG
// Uncomment to force-enable 128 virtual pins
//#define BLYNK_USE_128_VPINS
// Uncomment to disable fancy logo
//#define BLYNK_NO_FANCY_LOGO
// Uncomment to enable 3D fancy logo
//#define BLYNK_FANCY_LOGO_3D
// Uncomment to enable experimental functions.
//#define BLYNK_EXPERIMENTAL
// Uncomment to disable all float/double usage
//#define BLYNK_NO_FLOAT
// Uncomment to switch to direct-connect mode
//#define BLYNK_USE_DIRECT_CONNECT
// Uncomment to append command body to header (uses more RAM)
//#define BLYNK_SEND_ATOMIC
// Split whole command into chunks (in bytes)
//#define BLYNK_SEND_CHUNK 64
// Wait after sending each chunk (in milliseconds)
//#define BLYNK_SEND_THROTTLE 10
#endif
IDE serial debugging of case where failure occurs:
SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
[55] Connecting to Grace 3G
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
connected with Grace 3G, channel 6
dhcp client start...
cnt
wifi evt: 0
ip:192.168.43.213,mask:255.255.255.0,gw:192.168.43.1
wifi evt: 3
[2560] Connected to WiFi
[2560] IP: 192.168.43.213
[2561]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on NodeMCU
[2570] Connecting to blynk-cloud.com:8080
[hostByName] request IP for: blynk-cloud.com
[hostByName] Host: blynk-cloud.com IP: 45.55.96.146
[3308] <[02|00|01|00] c2700ca3f8fa4bb9b03d8d6c778a8f40
[9310] Login timeout
IDE serial debugging of case where connection success occurs:
SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
[55] Connecting to Love
wifi evt: 2
sta config unchangedscandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt
connected with Love, channel 3
dhcp client start...
wifi evt: 0
ip:192.168.88.251,mask:255.255.255.0,gw:192.168.88.1
wifi evt: 3
[329] Connected to WiFi
[355] IP: 192.168.88.251
[382]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on NodeMCU
[536] Connecting to blynk-cloud.com:8080
[hostByName] request IP for: blynk-cloud.com
[hostByName] Host: blynk-cloud.com IP: 45.55.96.146
:ref 1
[1118] <[02|00|01|00] c2700ca3f8fa4bb9b03d8d6c778a8f40
:wr 37 37 0
:wrc 37 37 0
:ack 37
:rn 5
:c0 1, 5
[1340] >[00|00|01|00|C8]
[1340] Ready (ping: 221ms).
[1340] Free RAM: 47040
[1407] <[11|00|02|00]Hver[00]0.5.4[00]h-beat[00]30[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Mar 26 2019 15:06:36[00]
:wr 77 77 0
:wrc 77 77 0
:ack 77
:rn 5
:c0 1, 5
[1741] >[00|00|02|00|C8]
When I connect via PC internet browser via tethered smartphone by sending:
http://blynk-cloud.com/c2700ca3f8fa4bb9b03d8d6c778a8f40/project
{"id":478616176,"parentId":-1,"isPreview":false,"name":"Washing Machine Aces","createdAt":1550243820511,"updatedAt":1553617722320,"widgets":[{"type":"LED","id":57718,"x":3,"y":3,"color":600084223,"width":1,"height":1,"tabId":0,"label":"washing machine power","isDefaultColor":true,"deviceId":0,"pinType":"VIRTUAL","pin":0,"pwmMode":false,"rangeMappingOn":false,"min":0.0,"max":0.0,"value":"0"},{"type":"TERMINAL","id":61856,"x":0,"y":0,"color":255,"width":8,"height":3,"tabId":0,"label":"Type 88 Then Send To Start","isDefaultColor":true,"deviceId":0,"pinType":"VIRTUAL","pin":1,"pwmMode":false,"rangeMappingOn":false,"min":0.0,"max":0.0,"autoScrollOn":true,"terminalInputOn":true,"textLightOn":true,"attachNewLine":false},{"type":"NOTIFICATION","id":99445,"x":0,"y":3,"color":600084223,"width":2,"height":1,"tabId":0,"isDefaultColor":true,"androidTokens":{"3aa1bab8731f139a":"e7Aqm0MxDYI:APA91bEwtGaKv8PXHF8A5K5c_RXvuRUHQfUiTtODOxn8HPYSG1X8JiDd3GedbKd2tDurl63bC5HXLdsbHlk-q3Jxa2IywCyojB-MhVF3QeQwfyGAr5zFi3UVqMsKq-DZg0P0NcdI7voS","d59ea18322402a4f":"dBF3CiPZGKA:APA91bHiIeR5ztQhKQCv7Qlae6jkntYoSRnXrp3uJ3S676WUHyOaDoj_rqQBUkrJMXuGXTa695FwBLYOdENaPIYQmgsrSjhnANcI9ZvYd-lYer_v8pfw4FT9FxNcABUyf9GPc-XTf9GN"},"notifyWhenOffline":true,"notifyWhenOfflineIgnorePeriod":0,"priority":"normal","soundUri":"content://settings/system/notification_sound"}],"devices":[{"id":0,"name":"washing machine ","boardType":"ESP8266","vendor":"washing machine ","connectionType":"WI_FI","isUserIcon":false}],"theme":"Blynk","keepScreenOn":false,"isAppConnectedOn":false,"isNotificationsOff":false,"isShared":false,"isActive":true,"widgetBackgroundOn":false,"color":0,"isDefaultColor":true}
Here is the Arduino ESP8266 HTTP client example sketch that does work OK via the tethered smartphone:
/**
BasicHTTPClient.ino
Created on: 24.05.2015
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
void setup() {
USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("Love", "A850F3619D");
//WiFiMulti.addAP("Grace 3G, "11111111");
}
void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
//http.begin("http://192.168.1.12/test.html"); //HTTP
http.begin("http://blynk-cloud.com/c2700ca3f8fa4bb9b03d8d6c778a8f40/project"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
delay(10000);
}
Here is the Serial debug output from that Example sketch:
SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
[SETUP] WAIT 4...
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 2 (7a0)
[SETUP] WAIT 3...
state: 2 -> 0 (4)
reconnect
wifi evt: 1
STA disconnect: 202
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
connected with Grace 3G, channel 6
dhcp client start...
cnt
wifi evt: 0
ip:192.168.43.213,mask:255.255.255.0,gw:192.168.43.1
wifi evt: 3
[SETUP] WAIT 2...
[SETUP] WAIT 1...
[WIFI][APlistAdd] add SSID: Grace 3G
[HTTP] begin...
[HTTP-Client][begin] url: http://blynk-cloud.com/c2700ca3f8fa4bb9b03d8d6c778a8f40/project
[HTTP-Client][begin] host: blynk-cloud.com port: 80 url: /c2700ca3f8fa4bb9b03d8d6c778a8f40/project
[HTTP] GET...
[hostByName] request IP for: blynk-cloud.com
[hostByName] Host: blynk-cloud.com IP: 45.55.96.146
:ref 1
[HTTP-Client] connected to blynk-cloud.com:80
[HTTP-Client] sending request header
-----
GET /c2700ca3f8fa4bb9b03d8d6c778a8f40/project HTTP/1.1
Host: blynk-cloud.com
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
-----
:wr 182 182 0
:wrc 182 182 0
:ack 182
:rn 536
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 200 OK'
[HTTP-Client][handleHeaderResponse] RX: 'content-type: application/json;charset=utf-8'
[HTTP-Client][handleHeaderResponse] RX: 'access-control-allow-origin: *'
[HTTP-Client][handleHeaderResponse] RX: 'content-length: 1658'
[HTTP-Client][handleHeaderResponse] RX: 'connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 200
[HTTP-Client][handleHeaderResponse] size: 1658
[HTTP] GET... code: 200
:c0 1, 536
:rn 536
:rch 536, 536
:c 1, 536, 1072
:c0 1, 536
:rn 188
:rcl
:abort
:c0 1, 188
[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: 1658).
[HTTP-Client][end] tcp is closed
{"id":478616176,"parentId":-1,"isPreview":false,"name":"Washing Machine Aces","createdAt":1550243820511,"updatedAt":1553605720648,"widgets":[{"type":"LED","id":57718,"x":3,"y":3,"color":600084223,"width":1,"height":1,"tabId":0,"label":"washing machine power","isDefaultColor":true,"deviceId":0,"pinType":"VIRTUAL","pin":0,"pwmMode":false,"rangeMappingOn":false,"min":0.0,"max":0.0,"value":"0"},{"type":"TERMINAL","id":61856,"x":0,"y":0,"color":255,"width":8,"height":3,"tabId":0,"label":"Type 88 Then Send To Start","isDefaultColor":true,"deviceId":0,"pinType":"VIRTUAL","pin":1,"pwmMode":false,"rangeMappingOn":false,"min":0.0,"max":0.0,"autoScrollOn":true,"terminalInputOn":true,"textLightOn":true,"attachNewLine":false},{"type":"NOTIFICATION","id":99445,"x":0,"y":3,"color":600084223,"width":2,"height":1,"tabId":0,"isDefaultColor":true,"androidTokens":{"3aa1bab8731f139a":"e7Aqm0MxDYI:APA91bEwtGaKv8PXHF8A5K5c_RXvuRUHQfUiTtODOxn8HPYSG1X8JiDd3GedbKd2tDurl63bC5HXLdsbHlk-q3Jxa2IywCyojB-MhVF3QeQwfyGAr5zFi3UVqMsKq-DZg0P0NcdI7voS","d59ea18322402a4f":"dBF3CiPZGKA:APA91bHiIeR5ztQhKQCv7Qlae6jkntYoSRnXrp3uJ3S676WUHyOaDoj_rqQBUkrJMXuGXTa695FwBLYOdENaPIYQmgsrSjhnANcI9ZvYd-lYer_v8pfw4FT9FxNcABUyf9GPc-XTf9GN"},"notifyWhenOffline":true,"notifyWhenOfflineIgnorePeriod":0,"priority":"normal","soundUri":"content://settings/system/notification_sound"}],"devices":[{"id":0,"name":"washing machine ","boardType":"ESP8266","vendor":"washing machine,"connectionType":"WI_FI","isUserIcon":false}],"theme":"Blynk","keepScreenOn":false,"isAppConnectedOn":false,"isNotificationsOff":false,"isShared":false,"isActive":true,"widgetBackgroundOn":false,"color":0,"isDefaultColor":true}
[HTTP-Client][end] tcp is closed
:ur 1
:del
I see that when I try to connect via the tethered wifi, blynk-cloud doesn’t authenticate, Im pretty sure that the TCP/IP side is OK
Patrick