void* doNewThread(void* Iterations) { int i, sockfd, nIterations = *((int*)Iterations); // void* to int* and value char buffer[BUFSIZE]; struct sockaddr_in serv_addr; while (nIterations--) { // AF_INET remote o local access if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) <0) putConsole("socket() failed"); else { serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(IP_ADDRESS); serv_addr.sin_port = htons(PORT); if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <0) putConsole("connect() failed"); else { // now the sockfd can be used to communicate to the server write(sockfd, "GET /index.html \r\n", 18); // note second space is a delimiter and important // this displays the raw HTML file as received by the browser while( (i=read(sockfd,buffer,BUFSIZE)) > 0) { buffer[i] = 0; putConsole(buffer); } close(sockfd); } } } // nIterations return 0; }
int main(void) { unsigned char iloop, jloop; char AddrString[30]; char ConstString[256]; InitializeSystem(); unsigned char temp, temp1, temp2, temp3, temp4; unsigned char ones_char, tens_char, huns_char; int16_t change_cnt; sprintf(OutString, "WiFly Pass_thru\nDemo"); putsLCD(OutString); // JKW starts here Delayms(5000); sprintf(OutString,"$$$"); putsWiFly(OutString); putsConsole(OutString); Delayms(5000); sprintf(OutString,"set comm open [\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set wlan name Hogwarts\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set wlan phrase pooKums496\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set ftp timer 40\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set comm close ]\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"save\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); // sprintf(OutString,"get everything\r\n"); // putsConsole(OutString); // putsWiFly(OutString); Delayms(200); sprintf(OutString, "Aug31 7:44AM \nputs only "); // columns 41, 59 putsConsole(OutString); Delayms(200); setLCDC(0x00); // point to 1st line Delayms(200); putsLCD(OutString); Delayms(2000); sprintf(OutString, "\r\n"); putsConsole(OutString); change_cnt = 0; for (iloop = 0; iloop <=5; iloop++) { Delayms(5000); sprintf(AddrString,"ftp put zzaq29_000.txt\r\n"); temp1 = (iloop % 10); ones_char = temp1 + 0x30; temp2 = (iloop - temp1)/10; tens_char = temp2 + 0x30; temp3 = (iloop - temp2*10 - temp1)/100; huns_char = temp3 + 0x30; AddrString[15] = huns_char; AddrString[16] = tens_char; AddrString[17] = ones_char; Delayms(5000); putsConsole(AddrString); Delayms(1000); putsWiFly(AddrString); sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568"); // 1009 temp4 = ConstString[change_cnt] - 0x01; if (temp4 < 0x30) { temp4 = 0x30; change_cnt++; if (change_cnt == 251) {change_cnt = 0;} temp4 = ConstString[change_cnt] - 0x01; } if ((temp4 < 0x41) && (temp4 > 0x39)) temp4 = 0x39; ConstString[change_cnt] = temp4; change_cnt++; if (change_cnt == 251) {change_cnt = 0;} temp = 0x00; while (temp != '.') {temp = U1RXREG; Delayms(10);} temp = 0x00; while (temp != '.') {temp = U1RXREG; Delayms(10);} temp = 0x00; while (temp != '.') {temp = U1RXREG; Delayms(10);} temp = 0x00; while (temp != '.') {temp = U1RXREG; Delayms(10);} temp = 0x00; while (temp != '.') {temp = U1RXREG; Delayms(10);} while (U1RXREG != '1') // [ = 0x5B, ] = 0x5D { putConsole(U1RXREG); Delayms(200); } putsConsole(ConstString); Delayms(1000); putsWiFly(ConstString); Delayms(10000); // Delayms(10000); sprintf(ConstString,"$$$"); putsConsole(ConstString); Delayms(1000); putsWiFly(ConstString); Delayms(1000); setLCDC(0x00); // point to 1st line Delayms(200); sprintf(OutString, "iloop = \nLoop to 25 "); OutString[9] = (char) (0x30 + iloop %10); OutString[8] = '0'; if ((iloop >= 10) && (iloop <= 19)) OutString[8] = '1'; if ((iloop >= 20) && (iloop <= 29)) OutString[8] = '2'; putsLCD(OutString); Delayms(10000); } // JKW ends here while(1) { // check if S4 pressed to trigger WiFly factory restoral if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS)) { sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n"); putsConsole(OutString); // drive GPIO9 high for 10ms before resetting the module RN_GPIO9 = 1; Delayms(1000); // Assert RESET for 10ms RN_RESET = 0; Delayms(100); RN_RESET = 1; Delayms(100); // toggle GPIO9 5 times, delaying at least 1 sec between toggles RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); // now toggle RESET to reboot the module and apply factory default settings RN_RESET = 0; Delayms(100); RN_RESET = 1; // wait for user to release S4 while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS)); } } } // main
int main(void) { unsigned char jloop; unsigned int iloop; char AddrString[30]; char ConstString[256]; InitializeSystem(); unsigned char temp, temp1, temp2, temp3, temp4; unsigned char ones_char, tens_char, huns_char; int16_t change_cnt; ODCAbits.ODA6 = 0; // This is for the Explorer-16 Demo Board TRISAbits.TRISA6 = 0; // This is for the Explorer-16 Demo Board // ODCCbits.ODC2 = 0; // TRISCbits.TRISC2 = 0; unsigned long i; GreenLEDState = 0; RedLEDState = 0; RTCCInit(); // initialization includes set the time and date TimeMinBinary = 0; while (TimeMinBinary < 3) { if (TenSecondTick == 1) { RTCCgrab(); TimeHourBinary = mRTCCDec2Bin(TimeHourBCD); TimeMinBinary = mRTCCDec2Bin(TimeMinBCD); TimeSecBinary = mRTCCDec2Bin(TimeSecBCD); TimeDayOfWeekBinary = mRTCCDec2Bin(TimeDayOfWeekBCD); TimeDayBinary = mRTCCDec2Bin(TimeDayBCD); TimeMonthBinary = mRTCCDec2Bin(TimeMonthBCD); TimeYearBinary = mRTCCDec2Bin(TimeYearBCD); sprintf(OutString, " : : \n / / 20 "); // columns 41, 59 // sprintf(OutString, "Sept4 1:00PM \nputs only "); // columns 41, 59 temp1 = (TimeHourBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeHourBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[0] = tens_char; OutString[1] = ones_char; temp1 = (TimeMinBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeMinBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[3] = tens_char; OutString[4] = ones_char; temp1 = (TimeSecBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeSecBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[6] = tens_char; OutString[7] = ones_char; temp1 = (TimeDayOfWeekBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeDayOfWeekBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[17] = tens_char; OutString[18] = ones_char; temp1 = (TimeDayBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeDayBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[20] = tens_char; OutString[21] = ones_char; temp1 = (TimeMonthBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeMonthBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[23] = tens_char; OutString[24] = ones_char; temp1 = (TimeYearBinary % 10); ones_char = temp1 + 0x30; temp2 = (TimeYearBinary - temp1)/10; tens_char = temp2 + 0x30; OutString[28] = tens_char; OutString[29] = ones_char; Delayms(200); setLCDC(0x00); // point to 1st line Delayms(2000); putsLCD(OutString); TenSecondTick = 0; } // if (TenSecondTick == 1) } // while(TimeMinBinary < 4) sprintf(OutString, "WiFly Pass_thru\nDemo"); putsLCD(OutString); // JKW starts here Delayms(5000); sprintf(OutString,"$$$"); putsWiFly(OutString); putsConsole(OutString); Delayms(5000); sprintf(OutString,"set comm open [\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); // sprintf(OutString,"set wlan ssid AMI\r\n"); // sprintf(OutString,"set wlan ssid Arthur$and$Matts$Internet\r\n"); sprintf(OutString,"set wlan ssid Hogwarts\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); // sprintf(OutString,"set wlan phrase hot7blue\r\n"); sprintf(OutString,"set wlan phrase pooKums496\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set ftp timer 80\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set comm close ]\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set ftp dir /jackwaterman\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set ftp user waterallusers\r\n"); putsConsole(OutString); putsWiFly(OutString); Delayms(1000); sprintf(OutString,"set ftp pass aRkeO7755123!\r\n"); putsConsole(OutString); putsWiFly(OutString); //User=jaycen is now waterallusers //Pass=jWes232740 is now aRkeO7755123! //Dir=../../ is now /jackwaterman Delayms(1000); sprintf(OutString,"save\r\n"); putsConsole(OutString); putsWiFly(OutString); // Delayms(1000); // sprintf(OutString,"get everything\r\n"); // putsConsole(OutString); // putsWiFly(OutString); Delayms(200); sprintf(OutString, "Sept7 8:00AM \nputs only "); // columns 41, 59 putsConsole(OutString); Delayms(200); setLCDC(0x00); // point to 1st line Delayms(200); putsLCD(OutString); Delayms(2000); sprintf(OutString, "\r\n"); putsConsole(OutString); change_cnt = 0; // sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568"); // 1009 for (iloop = 0; iloop <=999; iloop++) { Delayms(500); // worked well with 5000 sprintf(AddrString,"ftp put sept9__000.txt\r\n"); // sprintf(AddrString,"ftp put arthur_000.txt\r\n"); temp1 = (iloop % 10); ones_char = temp1 + 0x30; temp2 = ((iloop - temp1) % 100)/10; tens_char = temp2 + 0x30; temp3 = (iloop - temp2*10 - temp1)/100; huns_char = temp3 + 0x30; AddrString[15] = huns_char; AddrString[16] = tens_char; AddrString[17] = ones_char; Delayms(500); // worked well with 5000 putsConsole(AddrString); Delayms(500); putsWiFly(AddrString); sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568"); // 1009 temp4 = ConstString[change_cnt] - 0x01; if (temp4 < 0x30) { temp4 = 0x30; change_cnt++; if (change_cnt == 251) {change_cnt = 0;} temp4 = ConstString[change_cnt] - 0x01; } if ((temp4 < 0x41) && (temp4 > 0x39)) temp4 = 0x39; ConstString[change_cnt] = temp4; change_cnt++; if (change_cnt == 251) {change_cnt = 0;} temp = 0x00; kickout_seconds = 0; // kicks out if takes longer than 2 minutes RTCCgrab(); TimeHourBinary = mRTCCDec2Bin(TimeHourBCD); TimeMinBinary = mRTCCDec2Bin(TimeMinBCD); TimeSecBinary = mRTCCDec2Bin(TimeSecBCD); time_mark1 = TimeHourBinary*3600 + TimeMinBinary*60+ TimeSecBinary; TimeHourBinarySave = TimeHourBinary; while ( (U1RXREG != '1') && (kickout_seconds < 60) ) // [ = 0x5B, ] = 0x5D { putConsole(U1RXREG); RTCCgrab(); TimeHourBinary = mRTCCDec2Bin(TimeHourBCD); TimeMinBinary = mRTCCDec2Bin(TimeMinBCD); TimeSecBinary = mRTCCDec2Bin(TimeSecBCD); time_mark2 = TimeHourBinary*3600 + TimeMinBinary*60+ TimeSecBinary; if (TimeHourBinary < TimeHourBinarySave) time_mark2 = time_mark2 + 24*3600; kickout_seconds = time_mark2 - time_mark1; Delayms(200); } if (kickout_seconds < 60) { putsConsole(ConstString); Delayms(500); putsWiFly(ConstString); // Delayms(7000); // works OK when ftp_timeout = 40, 1 every 12 sec // Delayms(21000);// works OK when ftp_timeout = 40, 1 every 24 sec Delayms(12000); // works OK when ftp_timeout = 40, 1 every 16 sec } sprintf(ConstString,"$$$"); putsConsole(ConstString); Delayms(500); putsWiFly(ConstString); Delayms(500); setLCDC(0x00); // point to 1st line Delayms(200); sprintf(OutString, "iloop = \nLoop to 1000 "); temp1 = (iloop % 10); ones_char = temp1 + 0x30; // temp2 = (iloop - temp1)/10; temp2 = ((iloop - temp1) % 100)/10; tens_char = temp2 + 0x30; temp3 = (iloop - temp2*10 - temp1)/100; huns_char = temp3 + 0x30; OutString[8] = huns_char; OutString[9] = tens_char; OutString[10] = ones_char; putsLCD(OutString); Delayms(1000); // worked well with 10000 } // JKW ends here while(1) { // check if S4 pressed to trigger WiFly factory restoral if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS)) { sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n"); putsConsole(OutString); // drive GPIO9 high for 10ms before resetting the module RN_GPIO9 = 1; Delayms(1000); // Assert RESET for 10ms RN_RESET = 0; Delayms(100); RN_RESET = 1; Delayms(100); // toggle GPIO9 5 times, delaying at least 1 sec between toggles RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); RN_GPIO9 = 1; Delayms(1200); RN_GPIO9 = 0; Delayms(1200); // now toggle RESET to reboot the module and apply factory default settings RN_RESET = 0; Delayms(100); RN_RESET = 1; // wait for user to release S4 while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS)); } } } // main
/******************************************************************************* Function: void ConsoleUartIntHandler(void) Remarks: UART 1 interrupt handler is set at priority level 2 with software context saving */ void ConsoleUartIntHandler(void) { unsigned char byteReceived; // Is this an RX interrupt? if (INTGetFlag(INT_SOURCE_UART_RX(UART_CONSOLE))) { while (UARTReceivedDataIsAvailable(UART_CONSOLE) != 0) { byteReceived = UARTGetDataByte(UART_CONSOLE); //Console Interrupt - In Self Test Mode if(self_TESTMode == TRUE) { ConsoleMsgCallback_selfTest(); } //Console Interrupt - RN1723 Command Mode else if(RN_UartCmdMode == 1) { //Exit console mode if 'ESC' if(byteReceived == ESC) { RN_UartCmdMode = FALSE; RN_DATA_MODE(); memset(consoleMsg, '\0', sizeof(consoleMsg)); } else { while(!UARTTransmitterIsReady(UART_WIFLY)); UARTSendDataByte(UART_WIFLY, byteReceived); } } else { PIC32_ConsoleMode = TRUE; putConsole(byteReceived); if(byteReceived == CR) { PrintConsoleMenu(); } else if(byteReceived == LF) { //Ignore Line Feed } else if(byteReceived == BACKSPACE) { consoleMsg[(strlen(consoleMsg)-1)] = '\0'; } else if(byteReceived == ESC) { PIC32_ConsoleMode = FALSE; memset(consoleMsg, '\0', sizeof(consoleMsg)); } else { consoleMsg[strlen(consoleMsg)] = byteReceived; } } } // Clear the RX interrupt Flag INTClearFlag(INT_SOURCE_UART_RX(UART_CONSOLE)); } // We don't care about the TX interrupt if (INTGetFlag(INT_SOURCE_UART_TX(UART_CONSOLE)) ) { INTClearFlag(INT_SOURCE_UART_TX(UART_CONSOLE)); } }
// ***************************************************************************** // Send a null terminated string to the Console serial port // ***************************************************************************** void putsConsole(char *s) { while(*s) // loop until *s == '\0' the end of the string putConsole(*s++); // send the character and point to the next one }