HI, stucked once again.
I’m trying to establish an mqtt connection, but I’m getting “cannot allocate pbuf packet” from lwip. Any clue?
This is my code
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>/* FreeRTOS includes. */
#include “FreeRTOS.h”
#include “task.h”
#include “queue.h”#include “lwip/api.h”
#define usTaskStackSize 1024#include “MQTTClient/MQTTClient.h”
#include “wifi_conf.h”
#define MQTT_SELECT_TIMEOUT 1
static void messageArrived(MessageData* data)
{
DiagPrintf(“Message arrived on topic %s: %s\n”, data->topicName->lenstring.data, (char *)data->message->payload);
}void MQTT_Msg_Received()
{
/* To avoid gcc warnings /
//( void ) pvParameters;
DiagPrintf(“MQTT Recv\n”);
/ connect to gpssensor.ddns.net, subscribe to a topic, send and receive messages regularly every 5 sec /
MQTTClient client;
Network network;
unsigned char sendbuf[512], readbuf[80];
int rc = 0, count = 0;
MQTTPacket_connectData connectData = MQTTPacket_connectData_initializer;
char address = “192.168.1.239”;
char* sub_topic = “Ameba/test/#”;
char* pub_topic = “Ameba/Publish”;memset(readbuf, 0x00, sizeof(readbuf));
DiagPrintf(“Network Init\n”);
NetworkInit(&network);
DiagPrintf(“Network Up\n”);
MQTTClientInit(&client, &network, 30000, sendbuf, sizeof(sendbuf), readbuf, sizeof(readbuf));
DiagPrintf(“Client MQTT started\n”);while(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS) {
DiagPrintf( “Wiating for Wi-Fi.\n”);
vTaskDelay(5000 / portTICK_PERIOD_MS);}
DiagPrintf( “Wi-Fi connected.\n”);
DiagPrintf( “Connect Network "%s"\n”, address);
while ((rc = NetworkConnect(&network, address, 1883)) != 0){
DiagPrintf( “Return code from network connect is %d\n”, rc);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
DiagPrintf( “"%s" Connected\n”, address);connectData.MQTTVersion = 3;
connectData.clientID.cstring = “FT1_018”;DiagPrintf( “Start MQTT connection\n”);
while ((rc = MQTTConnect(&client, &connectData)) != 0){
DiagPrintf( “Return code from MQTT connect is %d\n”, rc);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
DiagPrintf( “MQTT Connected\n”);DiagPrintf( “Subscribe to Topic: %s\n”, sub_topic);
if ((rc = MQTTSubscribe(&client, sub_topic, QOS2, messageArrived)) != 0)
DiagPrintf( “Return code from MQTT subscribe is %d\n”, rc);DiagPrintf( “Publish Topics: %s\n”, pub_topic);
while (1)
{
MQTTMessage message;
char payload[300];if (++count == 0) count = 1; message.qos = QOS1; message.retained = 0; message.payload = payload; sprintf(payload, "hello from AMEBA %d", count); message.payloadlen = strlen(payload); if ((rc = MQTTPublish(&client, pub_topic, &message)) != 0) DiagPrintf("Return code from MQTT publish is %d\n", rc); if ((rc = MQTTYield(&client, 1000)) != 0) DiagPrintf("Return code from yield is %d\n", rc); vTaskDelay(5000);
}
/* do not return */
}void init()
{
int rc;DiagPrintf(“Task started\n”);
wifi_on(RTW_MODE_STA);rc=wifi_connect(“Chano2”,RTW_SECURITY_WPA_TKIP_PSK,“*********”,6,8,-1,NULL);
if (rc == RTW_SUCCESS)
DiagPrintf(“Connected to Wifi \n”);
else
DiagPrintf(“Not connected %d\n”,rc);while(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS) {
DiagPrintf( “Waiting for Wi-Fi.\n”);
vTaskDelay(5000 / portTICK_PERIOD_MS);}
rc=xTaskCreate(MQTT_Msg_Received, /* The function that implements the task. /
((const char)“MQTT-Task”), /* Just a text name for the task to aid debugging. /
usTaskStackSize + 128 , / The stack size is defined in FreeRTOSIPConfig.h. /
NULL, / The task parameter, not used in this case. /
tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, / The priority assigned to the task is defined in FreeRTOSConfig.h. */
NULL);while(1);
return;
}int main(void)
{
int rc;
DiagPrintf(“Main started\n”);
rc=xTaskCreate(init, ((const char*)“init”), usTaskStackSize + 128, NULL, tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, NULL);
vTaskStartScheduler();
DiagPrintf(“Scheduler Ended\n”);
}
and this is the console output
#calibration_ok:[2:19:11]
Main started
Task startedInitializing WIFI …
WIFI initializedRTL8721D[Driver]: set ssid [Chano2]
RTL8721D[Driver]: rtw_set_wpa_ie[1160]: AuthKeyMgmt = 0x2
RTL8721D[Driver]: rtw_restruct_sec_ie[4275]: no pmksa cached
RTL8721D[Driver]: start auth to 02:ec:da:36:02:48
RTL8721D[Driver]: auth alg = 2
RTL8721D[Driver]:
OnAuthClient:algthm = 0, seq = 2, status = 0, sae_msg_len = 0RTL8721D[Driver]: auth success, start assoc
RTL8721D[Driver]: association success(res=2)
RTL8721D[Driver]: ClientSendEAPOL[1650]: no use cache pmksa
RTL8721D[Driver]: set pairwise key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4)
RTL8721D[Driver]: set group key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4) keyid:1
Connected to Wifi
Waiting for Wi-Fi.Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packetWaiting for Wi-Fi.Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Cannot allocate pbuf to receive packet
Thx!