Help with TCP documentation for manual connection using AT commands and not supported GSM module

Hi everyone,

I’m having some issues while trying to get an Ai-thinker A9 (Pudding) module to work with Blynk, as it’s not supported by Blynk or TinyGSM libraries, I’m trying to connect it manually to Blynk cloud using AT commands based on the commands sent to a SIM800 module. For watching the AT commands sent to the SIM800 I used the StreamDebugger library and “#define DUMP_AT_COMMANDS” which prints on the serial monitor the AT commands sent to the module (explained below).

I’ve figured out a lot of them and found their equivalents with the A9 AT commands list but the main problem is that I’ve reached the point where the SIM800 module tries to connect to the Blynk server using TCP with the command “AT+CIPSTART=0,“TCP”,“blynk.cloud”,80” but shows the response “0, CONNECT FAIL” and never connects, using the A9 module with the command “AT+CIPSTART=“TCP”,“blynk.cloud”,80” connects without problems and responds with a “+CIPNUM:0” which is the connection number and then a “CONNECT OK” but I don’t know exactly the next steps as the SIM800 never connects.

Taking a dive in the library and Blynk documentation, I found that in order to get the device online it has to send the “login” command as it says here (Device Online/Offline Status | Blynk Documentation), looking into BlynkProtocol.h, there’s a line where the login command is sent: “sendCmd(BLYNK_CMD_HW_LOGIN, 1, authkey, strlen(authkey));” looking at the BLYNK_CMD_HW_LOGIN definition in BlynkProtocolDefs.h it corresponds to a 29.

Looking at the definition of sendCmd in BlynkProtocol.h, the parameters are (cmd, id, data, length, data2, length2), in this method, a BlynkHeader* hdr is created and its type(cmd), msg_id(id) and length are set based on the parameters, the data(authkey) is added later to the BlynkHeader and the last line where I see what happened to the authkey is “const size_t w = conn.write(buff + wlen, chunk);”

I guess later is used a command for sending the authkey and the login command to the server, something like AT+CIPSEND=CIPNUM,LENGTH,DATA where DATA contains the login command and the authkey, does anybody know the format of that DATA?

I’ve looked also the Blynk protocol documentation (Blynk Protocol | Blynk Documentation) and shows the structure of the messages which is: command(1 byte) message id (2 bytes) length/status (2 bytes) body (up to 2^15 bytes) but no separator or format.

Maybe I’m mixing things, sorry for that or for the confusion but my neurons are all mixed up.

If anyone has a working GSM module that connects to Blynk and sends data and want to take a look at the AT commands you need to add


#define DUMP_AT_COMMANDS

at the top of your sketch and


#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif

Instead of


TinyGsm modem(SerialAT);

You’ll need to download the StreamDebugger library from the library manager to do so.

Here´s an example using the AT command debugger on an Arduino UNO and SIM800:


* Change GPRS apm, user, pass, and Blynk auth token to run :)

**************************************************************/

#define BLYNK_TEMPLATE_ID "Template ID"

#define BLYNK_TEMPLATE_NAME "Template Name"

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space

#define DUMP_AT_COMMANDS

// Default heartbeat interval for GSM is 60

// If you want override this value, uncomment and set this option:

// #define BLYNK_HEARTBEAT 30

// Select your modem:

#define TINY_GSM_MODEM_SIM800

// #define TINY_GSM_MODEM_SIM808

// #define TINY_GSM_MODEM_SIM868

// #define TINY_GSM_MODEM_SIM900

// #define TINY_GSM_MODEM_SIM7000

// #define TINY_GSM_MODEM_SIM7000SSL

// #define TINY_GSM_MODEM_SIM7080

// #define TINY_GSM_MODEM_SIM5360

// #define TINY_GSM_MODEM_SIM7600

// #define TINY_GSM_MODEM_UBLOX

// #define TINY_GSM_MODEM_SARAR4

// #define TINY_GSM_MODEM_M95

// #define TINY_GSM_MODEM_BG96

// #define TINY_GSM_MODEM_A6

// #define TINY_GSM_MODEM_A7

// #define TINY_GSM_MODEM_M590

// #define TINY_GSM_MODEM_MC60

// #define TINY_GSM_MODEM_MC60E

// #define TINY_GSM_MODEM_ESP8266

// #define TINY_GSM_MODEM_XBEE

// #define TINY_GSM_MODEM_SEQUANS_MONARCH

#include <TinyGsmClient.h>

#include <BlynkSimpleTinyGSM.h>

// Set serial for debug console (to the Serial Monitor, default speed 115200)

#define SerialMon Serial

// Hardware Serial on Mega, Leonardo, Micro

#ifndef __AVR_ATmega328P__

#define SerialAT Serial1

// or Software Serial on Uno, Nano

#else

#include <SoftwareSerial.h>

SoftwareSerial SerialAT(2, 3); // RX, TX

#endif

// Your GPRS credentials, if any

const char apn[] = "YourAPN";

const char user[] = "";

const char pass[] = "";

// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

const char auth[] = "YourAuthToken";

#ifdef DUMP_AT_COMMANDS

#include <StreamDebugger.h>

StreamDebugger debugger(SerialAT, SerialMon);

TinyGsm modem(debugger);

#else

TinyGsm modem(SerialAT);

#endif

void setup()

{

// Set console baud rate

SerialMon.begin(115200);

delay(10);

// Set GSM module baud rate

SerialAT.begin(115200);

delay(6000);

// Restart takes quite some time

// To skip it, call init() instead of restart()

SerialMon.println("Initializing modem...");

modem.restart();

String modemInfo = modem.getModemInfo();

SerialMon.print("Modem Info: ");

SerialMon.println(modemInfo);

// Unlock your SIM card with a PIN

//modem.simUnlock("1234");

Blynk.begin(auth, modem, apn, user, pass);

}

void loop()

{

Blynk.run();

}

I hope someone knows about the format for the AT+CIPSEND explained above in order to get a device online or some orientation of where to find the next AT commands.

Thanks in advance and sorry If I missed something.

Best regards.

Turning-on Blynk debug with:

#define BLYNK_DEBUG

might help you, and reading this topic might help too…

Note that this was written when Blynk Legacy was in use. The protocol is basically the same, but some additional codes and statuses have been added, which you’ll see when you look at the relevant files in the library.

Pete.

Hi Pete,

I’m going to check that topic and then update the status of my project.

Thanks for the advice and for the quick response, I really appreciate it.

Best regards.