1. Modify ESP8266WiFi_0v25.js to do UDP and TCP
      Add UDPflag and CIPstartSTR.

      var at;
      var UDPflag=0;
      var CIPstartStr="";
      var socks = [];
      

    Modify the code to CIPstart a client in the create: function

      create : function(host, port) {
        /* Create a socket and return its index, host is a string, port is an integer.
        If host isn't defined, create a server socket */  
        if (host===undefined) {
    console.log("Server");
          sckt = MAXSOCKETS;
          socks[sckt] = "Wait";
          sockData[sckt] = "";
          at.cmd("AT+CIPSERVER=1,"+port+"\r\n", 10000, function(d) {
            if (d=="OK") {
              socks[sckt] = true;
            } else {
              socks[sckt] = undefined;
              setTimeout(function() {
                throw new Error("CIPSERVER failed ("+(d?d:"Timeout")+")");
              }, 0);
            }
          });
          return MAXSOCKETS;
        } else {  
    console.log("Client");
          var sckt = 0;
          while (socks[sckt]!==undefined) sckt++; // find free socket
          if (sckt>=MAXSOCKETS) throw new Error("No free sockets");
          socks[sckt] = "Wait";
          sockData[sckt] = "";
    
    if(UDPflag){//UDP client
     CIPstartStr='AT+CIPSTART='+sckt+',"UDP",'+JSON.stringify(host)+','+port+','+port+',0\r\n';
    
    }else{//TCP client
     CIPstartStr='AT+CIPSTART='+sckt+',"TCP",'+JSON.stringify(host)+','+port+'\r\n';
    }//end else
    at.cmd(CIPstartStr,10000, function cb(d) {
    

    Add code to set and reset the UDP flag

    "SetUDP":function(){ UDPflag=1;
    },
    "SetTCP" : function(){ UDPflag=0;
    },
    
      "getIP" : function(callback) {
    

    UDP.js placed in modules directory of WebIDE project.

    AT commands for UDP
    https://github.com/espressif/ESP8266_AT/wiki/at_example_0020000903
    https://gist.github.com/mokogobo/3f4d2f074305d4d84344

    https://cdn.sparkfun.com/assets/learn_tutorials/4/0/3/4A-ESP8266__AT_Instruction_Set__EN_v0.30.pdf
    AT+CIPSTART – Establish TCP connection or register UDP port, start connection
    Example
    AT+CIPSTART="TCP","192.168.101.110",1000
    Single connection
    (+CIPMUX=0)
    AT+CIPSTART=,,[,,]
    [,]
    Multiple connection
    (+CIPMUX=1)
    AT+CIPSTART=,,,[,,]
    [,]
    Response
    OK
    or
    ERROR
    If connection already exists, returns
    ALREAY CONNECT
    Parameters

    ID of the connection (0~4), for multi-connect

    string, "TCP" or "UDP"

    string, remote IP

    string, remote port
    []
    for UDP only
    [] In UDP transparent transmission, it has to be 0.
    [] 0
    : destination peer entity of UDP will not change.
    [] 1
    : destination peer entity of UDP can change once.
    [] 2
    : destination peer entity of UDP is allowed to change.
    Note: [] can only be used when [] is set.
    []
    default 0. unit: 500 milliseconds.
    [] 0
    : disable TCP keep-alive
    [] 1 ~ 7200
    : TCP keep-alive interval

    AT+CIPSTART – Function 2: R
    egister UDP port
    Example
    AT+CIPSTART="UDP", "192.168.101.110", 1000, 1002,
    2
    Single connection
    (AT
    +CIPMUX=0)
    AT+CIPSTART=, , [, ,
    ]
    Multiple connection
    (AT+CIPMUX=1
    )
    AT+CIPSTART=, , , [, , ]
    Response
    OK or
    ERROR
    If connection already exists, returns
    ALREADY CONNECT


    1 Attachment

About