Hi All,
-
I am trying to create a simple TCP client program that will be able to initiate TCP messages.
-
Here is my program:
#include "mongoose.h"
#include "mgos.h"
#include <xtensa/hal.h>
#include <math.h>
#include "string.h"
#include <esp_system.h>
const char *port1 = "tcp://192.168.4.2:1993";
//const char *port1 = "udp://192.168.4.2:1993";
struct mg_mgr mgr;
struct mg_connection *nc;
int freeheapspace;
int freefilespace;
int minfreeheapspace;
int timenow;
int timeup;
int i=0;
char messtring[2048];
char numstring[12];
uintptr_t swtt = 0;
static IRAM void led_timer_cb(void *arg) {
timeup = (int) mgos_uptime();
timenow = (int) time(0);
printf("System Up Time: %d Time Now %d \r\n",timeup,timenow);
messtring[0]='\0';
strcpy(messtring,"Time Up: "); sprintf(numstring,"%d",timeup); strcat(messtring,numstring);
strcat(messtring," Time Now: ");sprintf(numstring,"%d",timenow);strcat(messtring,numstring);
if (timeup>60) {
mg_send(nc, messtring, strlen(messtring));
}
mg_mgr_poll(&mgr,100);
(void) arg;
}
enum mgos_app_init_result mgos_app_init(void) {
mg_mgr_init(&mgr, NULL);
nc = mg_connect(&mgr, port1, NULL,NULL);
swtt= mgos_set_timer(5000, MGOS_TIMER_REPEAT, led_timer_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}
-
With UDP selected, I get a 5 second interval log of the time. With TCP selected, the ESP 32 crashes.
-
What is the problem? What is the simplest code that will achieve this simple end?
Thanks for your help,
JSW