Blynk C Programming for Cellular Modules With OpenCPU

Hey Fellow Blynk’ers

I have reviewed the various communities and forums around C Program examples and all seems to point to C++, Python and NodeJS, I have reviewed a few cellular modules available in the market place and having spent some time working on the OpenCPU (application runs on the module - Like Python on the ESP32) the integration and device cost is quote competitive as a finished product.

So my request is simple, anyone with example c code for Blynk would be great and am happy to share the library once tested and cleaned up. I will be working with NB-IoT modules for now.

Any code that you have will help, thanks in advance

Ok, so no takers here yet…

Any input on here is appreciated, I have reviewed the ‘TinyGSM’ files online and have found some info and found the following sequence (SIM800):

  • Initialise the module → Check SIM Pin and APN and and and…

This is where I seem to be missing something

  • Configure DNS Server Address = “8.8.8.8”,“8.8.4.4” (is this correct?)
  • Open the Connection = “TCP”,“ny3.blynk.cloud”,8442
    → found the “ny3” at the bottom of my web portal dashboard so used that server
    → 8442 is the default Port (according to SIM800 TinyGSM)
    → 8443 is secure Port (according to SIM800 TinyGSM)
    → “ny3.blynk.cloud” found IP Address: 64.225.16.22, anyone know if this is static or dynamic?

When I try these settings, I get a “Socket connection failed(code 566)” response, tried both default and secure ports, when I use the domain name.

When I try connect with the IP address, I get an “Open URC” and then 15mS later the “closed” URC is issued, so the connection is closed from the server side.

Here is my AT command log with time stamp, any comments welcome:

[2021-12-13_14:49:59:330]AT

[2021-12-13_14:49:59:330]OK
[2021-12-13_14:50:02:131]AT+CMEE=2

[2021-12-13_14:50:02:131]OK
[2021-12-13_14:50:07:120]AT+CPIN?

[2021-12-13_14:50:07:120]+CPIN: READY

[2021-12-13_14:50:07:120]OK
[2021-12-13_14:50:09:457]AT+CEREG?

[2021-12-13_14:50:09:457]+CEREG: 0,5

[2021-12-13_14:50:09:457]OK
[2021-12-13_14:50:13:116]AT+CFUN?

[2021-12-13_14:50:13:116]+CFUN: 1

[2021-12-13_14:50:13:116]OK
[2021-12-13_14:50:14:219]AT+COPS?

[2021-12-13_14:50:14:219]+COPS: 0,2,“65501”,9

[2021-12-13_14:50:14:219]OK
[2021-12-13_14:50:18:939]AT+CGATT?

[2021-12-13_14:50:18:939]+CGATT: 1

[2021-12-13_14:50:18:939]OK
[2021-12-13_14:50:25:033]AT+QIDNSCFG=0,“8.8.8.8”,“8.8.4.4”

[2021-12-13_14:50:25:033]OK
[2021-12-13_14:50:32:487]AT+QIOPEN=0,0,“TCP”,“ny3.blynk.cloud”,8442,0,1

[2021-12-13_14:50:32:487]OK
[2021-12-13_14:50:34:711]
[2021-12-13_14:50:34:711]+CSCON: 1
[2021-12-13_14:50:34:928]
[2021-12-13_14:50:34:928]+QIOPEN: 0,566
[2021-12-13_14:50:40:596]AT+QICLOSE=1

[2021-12-13_14:50:40:596]OK

[2021-12-13_14:50:40:596]CLOSE OK
[2021-12-13_14:50:44:539]AT+QIOPEN=0,1,“TCP”,“64.225.16.22”,8443,0,1

[2021-12-13_14:50:44:539]OK
[2021-12-13_14:50:45:124]
[2021-12-13_14:50:45:124]+QIOPEN: 1,0
[2021-12-13_14:50:45:625]
[2021-12-13_14:50:45:625]+QIURC: “closed”,1

As you discovered with your other testing, the port is 443…

Blynk has a number of servers around the world, and your account/project only lives on one of them. In your case that’s the New York server.

Using the blynk.cloud url obviously leaves you at the mercies of the DNS service that you happen to be using at the time, but Blynk instituted some clever processing to automatically re-route your connection to the correct server. However, this doesn’t work with HTTP(S) API calls, so you need to specify the correct server when making these calls.
Personally, I’d stick with ny3.blynk.cloud url as it’s not beyond the realms of possibility that the IP address may change in future.

Pete.

Update:
So discovered that on NB-IoT the connection is disconnected by the server side… not sure why

When I use LTE Cat1/2G I get a connect OK.

Any ideas on how to send the data packet?

I get the following "hex’ values back, which is 7 characters as opposed to 5.
15 03 01 00 02 02 46

These are the special characters:
Which equate to in hex: 1D 00 01 00 (MSG_HW_LOGIN NUL ID NUL)

Below AT Log
[2021-12-13_18:05:31:165]AT+QIACT?

[2021-12-13_18:05:31:165]+QIACT: 1,1,1,“10.95.8.124”

[2021-12-13_18:05:31:165]OK
[2021-12-13_18:05:34:469]AT+QIDNSCFG=1,“8.8.8.8”,“8.8.4.4”

[2021-12-13_18:05:34:469]OK
[2021-12-13_18:05:36:541]AT+QICFG=“dataformat”,0,1

[2021-12-13_18:05:36:541]OK
[2021-12-13_18:05:38:413]AT+QIOPEN=1,0,“TCP”,“blynk.cloud”,443,0,1

[2021-12-13_18:05:38:413]OK
[2021-12-13_18:05:39:018]
[2021-12-13_18:05:39:018]+QIOPEN: 0,0
[2021-12-13_18:05:41:864]AT+QISEND=0

[2021-12-13_18:05:41:864]> 5Ut4chLSRJ0Y8OUOmCcEW2inXYlEIYDO
[2021-12-13_18:05:44:021]
[2021-12-13_18:05:44:021]SEND OK
[2021-12-13_18:05:44:305]
[2021-12-13_18:05:44:305]+QIURC: “recv”,0,7
[2021-12-13_18:05:44:305]15030100020246

[2021-12-13_18:05:44:305]+QIURC: “closed”,0