Parallax-ESP Module Latest Hack

I took the liberty of updating the Parallax-ESP firmware code to fix some bugs and add some functions.
New functions:
1) Can hide and unhide the WiFi module from the programmer without rebooting module.
2) Can set IP address, Gateway, Mask and DNS server.
3) Can send and receive UDP packets.
Here is a sample program that demonstrates setting IP address and a UDP packet.
#include "wifi.h"
#include "simpletools.h"

fdserial *fd;
int handle;
char *reply;
char Buffer[1024];
unsigned char NTP[48];
char *Data;
char rqs[] = "time.windows.com";
int Port = 123;
time_t t;
struct tm *x;
int i;
unsigned long t1;


int main()
{
  fd = wifi_start(3, 4, 115200, USB_PGM_TERM);
  wifi_command("SET:station-ipaddr,101.1.1.42&101.1.1.4&255.255.255.0&101.1.1.1\r");
  wifi_join("<your ssid>", "<your password>");
  printi("Joined\r");
  //build udp connect
  sprintf(Buffer, "%c%s,%d\r", 0xDE, rqs, Port);
  reply = wifi_command(Buffer); 
  handle = -1;
  if (reply[1] == 'S')
    handle = reply[3] - '0';
  printi("handle: %d\r", handle);
  NTP[0] = 0x1b;
  wifi_send(handle, NTP, 48);
  pause(1000);
  wifi_recv(handle, NTP, 1024);
  wifi_disconnect(handle);
  for (i=0;i<48;i++)
    printi("%02x ", NTP[i]);
  t1 = NTP[40] << 24 | NTP[41] << 16 | NTP[42] << 8 | NTP[43];
  t1 = t1 - (25567 * 24 * 60 * 60);
  x = localtime(&t1);
  print("Date: %d/%d/%d\n", x->tm_mon+1, x->tm_mday, x->tm_year+1900);
  print("Time: %02d:%02d:%02d\n", x->tm_hour, x->tm_min, x->tm_sec);
  while(1)
  {
    pause(1000);
  } 
}
Since there is no function to do a UDP connection I had to hand code one. Setting the IP address has the following order IP, Gateway, Mask, and DNS.
This firmware is based on Expressif NONOS_SDK version 2.2.1. This is the same version that is used for their Arduino libraries.
To use the firmware just install this OTA file. If things don’t work out you can always load the original firmware back from Parallax’s website.

Mike

Parallax-ESP108.ota

Comments

  • iseries wrote: »
    I took the liberty of updating the Parallax-ESP firmware code to fix some bugs and add some functions.
    New functions:
    1) Can hide and unhide the WiFi module from the programmer without rebooting module.
    2) Can set IP address, Gateway, Mask and DNS server.
    3) Can send and receive UDP packets.

    Mike,
    All of these functions are very useful.

    Thanks
    Shawn

Sign In or Register to comment.