void setup() { ebox_init(); uart1.begin(115200); uart1.printf("\r\nuart1 9600 ok!"); w5500.begin(2, mac, lip, sub, gw, dns); attach_eth_to_socket(&w5500); w5500.getMAC (ip); uart1.printf("\r\nmac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5]); w5500.getIP (ip); uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); w5500.getSubnet(ip); uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); w5500.getGateway(ip); uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); uart1.printf("Network is ready.\r\n"); if(udp1.begin(0, 30000) == 0) uart1.printf("\r\nudp1 server creat ok! listen on 30000"); if(udp2.begin(1, 30001) == 0) uart1.printf("\r\nudp2 server creat ok! listen on 30001"); }
void setup() { ebox_init(); uart1.begin(9600); ret = sd.begin(); if(!ret) uart1.printf("\r\nsdcard init ok!"); f_mount(0, &fs); w5500.begin(mac,lip,sub,gw); attachEthToSocket(&w5500); attachSDCardToFat(&sd); w5500.getMAC (ip); uart1.printf("\r\nmac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0],ip[1],ip[2],ip[3],ip[4],ip[5]); w5500.getIP (ip); uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getSubnet(ip); uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getGateway(ip); uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); uart1.printf("Network is ready.\r\n"); if(udp1.begin(0,30000) == 0) uart1.printf("\r\nudp1 server creat ok! listen on 30000"); uart1.printf("\r\nret = %d",ret); ret = sd.getCID(buf); uart1.printf("\r\nret = %d",ret); uart1.printf((const char*)buf); ret = sd.getCSD(buf); uart1.printf("\r\nret = %d",ret); rl = sd.getCapacity(); x = (float)rl; uart1.printf("\r\n容量 = %f",x/1024/1024); res=f_getfree("/",&free_clust,&fss); uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize)); if(res==FR_OK) { uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize)); uart1.printf("该分区大小为:%dM\r\n",(fss->max_clust-2)*(fss->csize)/2048); uart1.printf("该分区空簇数为:%d\r\n",free_clust); uart1.printf("该分区空扇区数为:%d\r\n",free_clust*(fss->csize)); } else uart1.printf("获取分区空簇失败\r\n,res = %d",res); uart1.printf("\r\n"); }
void setup() { // Set the port whis to use for contactign us back Udp.begin(8888); // Sedn the message to the server if (Udp.sendPacket(buffer, 39, remoteIP, port) < 0) { Particle.publish("Error"); } }
// // UDP stuff // void sendUDPmessage( String msg, int port = 5100 ) { IPAddress multicast( 225, 1, 1, 1 ); UDP server; if ( server.begin( port ) ) { server.beginPacket( multicast, port ); server.write( msg ); server.endPacket(); server.stop(); } }
void loop() { if (WiFi.ready()) { if (firstTimeReady) { firstTimeReady = false; // First time we get WiFi.ready(), initialize the UDP listener. This happens // every time we reconnect to WiFi. mcastUdp.begin(MCAST_PORT); } if (!haveServerAddr && millis() - serverAddrLastCheck >= SERVER_ADDR_CHECK_RETRY_MS) { serverAddrLastCheck = millis(); // If we don't have a server IP address, request it periodically (every 20 seconds) Serial.printlnf("requesting server address at %s:%d", mcastAddr.toString().c_str(), MCAST_PORT); strcpy(udpBuffer, "\n"); mcastUdp.sendPacket(udpBuffer, strlen(udpBuffer), mcastAddr, MCAST_PORT); } int count = mcastUdp.receivePacket(udpBuffer, UDP_BUFFER_SIZE - 1); if (count > 0) { udpBuffer[count] = 0; // Handle a received UDP packet from the server with the IP address and port of the server int addr[4], port; if (sscanf(udpBuffer, "%u.%u.%u.%u:%u", &addr[0], &addr[1], &addr[2], &addr[3], &port) == 5) { serverAddr = IPAddress(addr[0], addr[1], addr[2], addr[3]); serverPort = port; haveServerAddr = true; Serial.printlnf("serverAddr=%s port=%d", serverAddr.toString().c_str(), serverPort); } } } else { // If WiFi disconnects, we need to reestablish listeners next time firstTimeReady = true; } }
void openSocket() { udp.stop(); // Get OpenThread interface index (OpenThread interface is named "th1" on all Mesh devices) uint8_t idx = 0; if_name_to_index("th1", &idx); Log.trace("th1 index = %u", idx); // Create UDP socket and bind to OpenThread interface auto ur = udp.begin(PORT, idx); Log.trace("UDP.begin() = %u", ur); // Subscribe to ff03::1:1001 HAL_IPAddress addr = {}; addr.v = 6; inet_inet_pton(AF_INET6, MULTICAST_ADDR, addr.ipv6); mcastAddr = addr; int r = udp.joinMulticast(mcastAddr); Log.trace("Subscribed to %s: %d", MULTICAST_ADDR, r); }
int WolClient::wake(const char* mac) { uint8_t contents[MAGIC_HEADER_LENGTH + REPEAT_MAC * MAC_BYTES]; uint8_t rawMac[MAC_BYTES]; parseMacAddress(mac, rawMac); UDP udp; udp.begin(port); udp.beginPacket(broadcastIP, port); for (int i = 0; i < MAGIC_HEADER_LENGTH; i++) { contents[i] = 0xFF; } for (uint8_t i = MAGIC_HEADER_LENGTH; i < sizeof contents; i++) { contents[i] = rawMac[(i - MAGIC_HEADER_LENGTH) % MAC_BYTES]; } udp.write(contents, sizeof contents); udp.endPacket(); udp.stop(); return TRUE; }
void setup() { eBoxInit(); uart1.begin(9600); w5500.begin(mac,lip,sub,gw); w5500.attchInterruputEvent(ethEvent); attachEthToSocket(&w5500); w5500.getMAC (ip); uart1.printf("mac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0],ip[1],ip[2],ip[3],ip[4],ip[5]); w5500.getIP (ip); uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getSubnet(ip); uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getGateway(ip); uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); uart1.printf("Network is ready.\r\n"); if(udp.begin(0,30000) == 0) uart1.printf("\r\nudp1 server creat ok! listen on 30000"); }