Ejemplo n.º 1
0
uint8_t REDFLY::disconnect(void)
{
  socketReset();
  memset(ipaddr, 0, sizeof(ipaddr));

  return cmd(PSTR(CMD_DISCONN));
}
Ejemplo n.º 2
0
uint8_t REDFLY::begin(uint8_t dhcp, uint8_t *ip, uint8_t *dns, uint8_t *gateway, uint8_t *netmask)
{
  uint8_t len;

  //reset sockets and IP addr
  socketReset();
  memset(ipaddr, 0, sizeof(ipaddr));
  memset(buffer, 0, sizeof(buffer));

  //dhcp or auto ip
  if(dhcp == 2) //Auto-IP
  {
    if(cmd(buffer, sizeof(buffer), PSTR(CMD_IPCONF IPCONF_AUTOIP)) == 0) //OKMACaddrIPaddrSUBNETGateway
    {
      memcpy(&ipaddr[0], &buffer[8], 4);
      return 0;
    }
    return 2;
  }
  else if(dhcp) //DHCP
  {
    if(cmd(buffer, sizeof(buffer), PSTR(CMD_IPCONF IPCONF_DHCP)) == 0) //OKMACaddrIPaddrSUBNETGateway
    {
      memcpy(&ipaddr[0], &buffer[8], 4);
      return 0;
    }
    return 1;
  }

  //static ip settings
  if(dns)
  {
    iptoa(dns, (char*)&buffer[0]);
    cmd(PSTR(CMD_DNSSERVER), (char*)buffer); //set DNS server (FW >= 4.3.0 required)
  }
  if(ip)
  {
    iptoa(ip, (char*)buffer);
    memcpy(ipaddr, ip, 4);
  }
  else
  {
    strcat_P((char*)buffer, PSTR("192.168.0.1"));
    ipaddr[0] = 192;
    ipaddr[1] = 168;
    ipaddr[2] = 0;
    ipaddr[3] = 1;
  }
  if(netmask)
  {
    strcat_P((char*)buffer, PSTR(","));
    len = strlen((char*)buffer);
    iptoa(netmask, (char*)&buffer[len]);
  }
  else
  {
    strcat_P((char*)buffer, PSTR(",255.255.255.0"));
  }
  if(gateway)
  {
    strcat_P((char*)buffer, PSTR(","));
    len = strlen((char*)buffer);
    iptoa(gateway, (char*)&buffer[len]);
  }

  return cmd(PSTR(CMD_IPCONF "0,"), (char*)buffer); //xxx.xxx.xxx.xxx,yyy.yyy.yyy.yyy,zzz.zzz.zzz.zzz
}
Ejemplo n.º 3
0
uint8_t REDFLY::disconnect(void)
{
  socketReset();

  return cmd(PSTR(CMD_DISCONN));
}