/* Arduino Tutorial 06 for FlashAir * Copyright (C) 2014 by Munehiro Doi, Fixstars Corporation * * This Library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with the Arduino Sd2Card Library. If not, see * . */ /* #include #include const int chipSelectPin = 10; Sd2CardExt card; uint8_t buffer[512]; */ void printByte(uint8_t value) { Serial.print(value >> 4, HEX); Serial.print(value & 0xF, HEX); } void printBytes(uint8_t* p, uint32_t len) { for (int i = 0; i < len; ++i) { printByte(p[i]); } } void printIPAddress(uint8_t* p) { Serial.print(p[0], DEC); Serial.print('.'); Serial.print(p[1], DEC); Serial.print('.'); Serial.print(p[2], DEC); Serial.print('.'); Serial.print(p[3], DEC); } // IPAddressをコピーする 2015,7/4 void copyIPAddress(uint8_t* p) { char str[8]; sprintf(str, "%d.", p[0]); strcpy(IPaddress,str); //"コピー sprintf(str, "%d.", p[1]); strcat(IPaddress,str); sprintf(str, "%d.", p[2]); strcat(IPaddress,str); sprintf(str, "%d", p[3]); strcat(IPaddress,str); } void printHex(uint8_t* p, uint32_t len) { int i = 0; while (i < len) { if ((i & 0xf) == 0) { //Serial.print(F("\n")); //削除 2015,7/4 //printByte(i >> 4); //削除 2015,7/4 //Serial.print(F(": ")); //削除 2015,7/4 } //printByte(*p++); //削除 2015,7/4 i++; } //Serial.print(F("\n")); //削除 2015,7/4 } char* inputText(char* buf, uint8_t len) { // Read characters until user inputs enter or buffer gets full. uint8_t i = 0; while (i < len - 1) { while (Serial.available() == 0); char c = Serial.read(); if (c == ';') break; buf[i] = c; i++; } buf[i] = 0; Serial.println(buf); return buf; } boolean iSDIO_status() { //Serial.print(F("\nRead iSDIO Status Register")); // Read iSDIO Status Register (E7 1.10 2.2.2.1) memset(buffer, 0, 0x200); if (!card.readExtMemory(1, 1, 0x400, 0x200, buffer)) { return false; } /* // Show values in the common status area. Serial.print(F("\n == iSDIO Status Registers == ")); Serial.print(F("\n [0400h] Command Write Status: ")); if (buffer[0x000] & 0x01) Serial.print(F("CWU ")); if (buffer[0x000] & 0x02) Serial.print(F("CWA ")); Serial.print(F("\n [0420h] iSDIO Status: ")); if (buffer[0x020] & 0x01) Serial.print(F("CRU ")); if (buffer[0x020] & 0x02) Serial.print(F("ESU ")); if (buffer[0x020] & 0x04) Serial.print(F("MCU ")); if (buffer[0x020] & 0x08) Serial.print(F("ASU ")); Serial.print(F("\n [0422h] iSDIO Int Enable: ")); if (buffer[0x022] & 0x01) Serial.print(F("CRU_ENA ")); if (buffer[0x022] & 0x02) Serial.print(F("ESU_ENA ")); if (buffer[0x022] & 0x04) Serial.print(F("MCU_ENA ")); if (buffer[0x022] & 0x08) Serial.print(F("ASU_ENA ")); Serial.print(F("\n [0424h] Error Status: ")); if (buffer[0x024] & 0x01) Serial.print(F("CRE ")); if (buffer[0x024] & 0x02) Serial.print(F("CWE ")); if (buffer[0x024] & 0x04) Serial.print(F("RRE ")); if (buffer[0x024] & 0x08) Serial.print(F("APE ")); Serial.print(F("\n [0426h] Memory Status: ")); if (buffer[0x026] & 0x01) Serial.print(F("MEX ")); if (buffer[0x026] & 0x02) Serial.print(F("FAT ")); for (int i = 0; i < 8; ++i) { uint8_t addr = 0x40 + i * 0x14; Serial.print(F("\n [04")); printByte(addr); Serial.print(F("h] Command Response Status #")); Serial.print(i + 1, DEC); Serial.print(F(": ")); if (buffer[addr] & 0x01) { Serial.print(F("id = ")); Serial.print(get_u16(buffer + addr + 2), DEC); Serial.print(F(", sequence id = ")); Serial.print(get_u32(buffer + addr + 4), DEC); Serial.print(F(", status = ")); switch (buffer[addr + 8]) { case 0x00: Serial.print(F("Initial")); break; case 0x01: Serial.print(F("Command Processing")); break; case 0x02: Serial.print(F("Command Rejected")); break; case 0x03: Serial.print(F("Process Succeeded")); break; case 0x04: Serial.print(F("Process Terminated")); break; default: Serial.print(F("Process Failed ")); Serial.print(buffer[addr + 8], HEX); break; } } else { Serial.print(F("Not registered")); } } // Show values in the application status area. Serial.print(F("\n == Wireless LAN Status Registers ==")); Serial.print(F("\n [0500h] DLNA Status: ")); if (buffer[0x100] & 0x01) Serial.print(F("ULR ")); if (buffer[0x100] & 0x02) Serial.print(F("DLU ")); if (buffer[0x100] & 0x04) Serial.print(F("CBR ")); if (buffer[0x100] & 0x08) Serial.print(F("CDR ")); Serial.print(F("\n [0501h] P2P Status: ")); if (buffer[0x101] & 0x01) Serial.print(F("ILU ")); if (buffer[0x101] & 0x02) Serial.print(F("FLU ")); Serial.print(F("\n [0502h] PTP Status: ")); if (buffer[0x102] & 0x01) Serial.print(F("RPO ")); if (buffer[0x102] & 0x02) Serial.print(F("RPD ")); if (buffer[0x102] & 0x04) Serial.print(F("RPC ")); if (buffer[0x102] & 0x08) Serial.print(F("CPI ")); if (buffer[0x102] & 0x10) Serial.print(F("DPI ")); if (buffer[0x102] & 0x20) Serial.print(F("CIL ")); Serial.print(F("\n [0504h] Application: ")); Serial.print(buffer[0x104]); Serial.print(F("\n [0506h] WLAN: ")); if ((buffer[0x106] & 0x01) == 0x00) Serial.print(F("No Scan, ")); if ((buffer[0x106] & 0x01) == 0x01) Serial.print(F("Scanning, ")); if ((buffer[0x106] & 0x06) == 0x00) Serial.print(F("No WPS, ")); if ((buffer[0x106] & 0x06) == 0x02) Serial.print(F("WPS with PIN, ")); if ((buffer[0x106] & 0x06) == 0x04) Serial.print(F("WPS with PBC, ")); if ((buffer[0x106] & 0x08) == 0x00) Serial.print(F("Group Client, ")); if ((buffer[0x106] & 0x08) == 0x08) Serial.print(F("Group Owner ")); if ((buffer[0x106] & 0x10) == 0x00) Serial.print(F("STA, ")); if ((buffer[0x106] & 0x10) == 0x10) Serial.print(F("AP, ")); if ((buffer[0x106] & 0x60) == 0x00) Serial.print(F("Initial, ")); if ((buffer[0x106] & 0x60) == 0x20) Serial.print(F("Infrastructure, ")); if ((buffer[0x106] & 0x60) == 0x40) Serial.print(F("Wi-Fi Direct, ")); if ((buffer[0x106] & 0x80) == 0x00) Serial.print(F("No Connection, ")); if ((buffer[0x106] & 0x80) == 0x80) Serial.print(F("Connected, ")); */ // Serial.print(F("\n [0508h] SSID: ")); for (int i = 0; i < 32 && buffer[0x108 + i] != 0; ++i) { //Serial.print((char)buffer[0x108 + i]); current_ssid[i] = (char)buffer[0x108 + i]; } /* Serial.print(F("\n [0528h] Encryption Mode: ")); switch (buffer[0x128]) { case 0 : Serial.print(F("Open System and no encryption")); break; case 1 : Serial.print(F("Open System and WEP")); break; case 2 : Serial.print(F("Shared Key and WEP")); break; case 3 : Serial.print(F("WPA-PSK and TKIP")); break; case 4 : Serial.print(F("WPA-PSK and AES")); break; case 5 : Serial.print(F("WPA2-PSK and TKIP")); break; case 6 : Serial.print(F("WPA2-PSK and AES")); break; default: Serial.print(F("Unknown")); } Serial.print(F("\n [0529h] Signal Strength: ")); Serial.print(buffer[0x129], DEC); Serial.print(F("\n [052Ah] Channel: ")); if (buffer[0x12A] == 0) Serial.print(F("No connection")); else Serial.print(buffer[0x12A], DEC); Serial.print(F("\n [0530h] MAC Address: ")); printBytes(buffer + 0x130, 6); Serial.print(F("\n [0540h] ID: ")); for (int i = 0; i < 16 && buffer[0x140 + i] != 0; ++i) { Serial.print((char)buffer[0x140 + i]); } Serial.print(F("\n [0550h] IP Address: ")); printIPAddress(buffer + 0x150); */ copyIPAddress(buffer + 0x150); // IPAddressを変数にコピーする 2015,7/4 /* Serial.print(F("\n [0554h] Subnet Mask: ")); printIPAddress(buffer + 0x154); Serial.print(F("\n [0558h] Default Gateway: ")); printIPAddress(buffer + 0x158); Serial.print(F("\n [055Ch] Preferred DNS Server: ")); printIPAddress(buffer + 0x15C); Serial.print(F("\n [0560h] Alternate DNS Server: ")); printIPAddress(buffer + 0x160); Serial.print(F("\n [0564h] Proxy Server: ")); if ((buffer[0x164] & 0x01) == 0x00) Serial.print(F("Disabled")); if ((buffer[0x164] & 0x01) == 0x01) Serial.print(F("Enabled")); Serial.print(F("\n [0570h] Date: ")); Serial.print(buffer[0x171] + 1980, DEC); Serial.print('-'); Serial.print(buffer[0x170] >> 4, DEC); Serial.print('-'); Serial.print(buffer[0x170] & 0xF, DEC); Serial.print(F("\n [0572h] Time: ")); Serial.print(buffer[0x173] >> 3, DEC); Serial.print(':'); Serial.print(buffer[0x172] << 3 | buffer[0x170] >> 3, DEC); Serial.print(':'); Serial.print((buffer[0x172] & 0x1F) * 2, DEC); Serial.print(F("\n [0574h] HTTP Status: ")); Serial.print(buffer[0x174] & 0xEF, DEC); if ((buffer[0x174] & 0x80) == 0x00) Serial.print(F(" (No Processing)")); if ((buffer[0x174] & 0x80) == 0x80) Serial.print(F(" (Processing)")); Serial.print(F("\n [0575h] Power Save Management: ")); if ((buffer[0x175] & 0x01) == 0x00) Serial.print(F("Power Save Mode Off")); if ((buffer[0x175] & 0x01) == 0x01) Serial.print(F("Power Save Mode On")); Serial.print(F("\n [0576h] File System Management: ")); if ((buffer[0x176] & 0x01) == 0x00) Serial.print(F("FS Information may be modified")); if ((buffer[0x176] & 0x01) == 0x01) Serial.print(F("FS Information shall not be modified")); Serial.println(); */ return true; } boolean read_iSDIO_status() { Serial.print(F("\nRead iSDIO Status Register")); // Read iSDIO Status Register (E7 1.10 2.2.2.1) memset(buffer, 0, 0x200); if (!card.readExtMemory(1, 1, 0x400, 0x200, buffer)) { return false; } // Show values in the common status area. Serial.print(F("\n == iSDIO Status Registers == ")); Serial.print(F("\n [0400h] Command Write Status: ")); if (buffer[0x000] & 0x01) Serial.print(F("CWU ")); if (buffer[0x000] & 0x02) Serial.print(F("CWA ")); Serial.print(F("\n [0420h] iSDIO Status: ")); if (buffer[0x020] & 0x01) Serial.print(F("CRU ")); if (buffer[0x020] & 0x02) Serial.print(F("ESU ")); if (buffer[0x020] & 0x04) Serial.print(F("MCU ")); if (buffer[0x020] & 0x08) Serial.print(F("ASU ")); Serial.print(F("\n [0422h] iSDIO Int Enable: ")); if (buffer[0x022] & 0x01) Serial.print(F("CRU_ENA ")); if (buffer[0x022] & 0x02) Serial.print(F("ESU_ENA ")); if (buffer[0x022] & 0x04) Serial.print(F("MCU_ENA ")); if (buffer[0x022] & 0x08) Serial.print(F("ASU_ENA ")); Serial.print(F("\n [0424h] Error Status: ")); if (buffer[0x024] & 0x01) Serial.print(F("CRE ")); if (buffer[0x024] & 0x02) Serial.print(F("CWE ")); if (buffer[0x024] & 0x04) Serial.print(F("RRE ")); if (buffer[0x024] & 0x08) Serial.print(F("APE ")); Serial.print(F("\n [0426h] Memory Status: ")); if (buffer[0x026] & 0x01) Serial.print(F("MEX ")); if (buffer[0x026] & 0x02) Serial.print(F("FAT ")); for (int i = 0; i < 8; ++i) { uint8_t addr = 0x40 + i * 0x14; Serial.print(F("\n [04")); printByte(addr); Serial.print(F("h] Command Response Status #")); Serial.print(i + 1, DEC); Serial.print(F(": ")); if (buffer[addr] & 0x01) { Serial.print(F("id = ")); Serial.print(get_u16(buffer + addr + 2), DEC); Serial.print(F(", sequence id = ")); Serial.print(get_u32(buffer + addr + 4), DEC); Serial.print(F(", status = ")); switch (buffer[addr + 8]) { case 0x00: Serial.print(F("Initial")); break; case 0x01: Serial.print(F("Command Processing")); break; case 0x02: Serial.print(F("Command Rejected")); break; case 0x03: Serial.print(F("Process Succeeded")); break; case 0x04: Serial.print(F("Process Terminated")); break; default: Serial.print(F("Process Failed ")); Serial.print(buffer[addr + 8], HEX); break; } } else { Serial.print(F("Not registered")); } } // Show values in the application status area. Serial.print(F("\n == Wireless LAN Status Registers ==")); Serial.print(F("\n [0500h] DLNA Status: ")); if (buffer[0x100] & 0x01) Serial.print(F("ULR ")); if (buffer[0x100] & 0x02) Serial.print(F("DLU ")); if (buffer[0x100] & 0x04) Serial.print(F("CBR ")); if (buffer[0x100] & 0x08) Serial.print(F("CDR ")); Serial.print(F("\n [0501h] P2P Status: ")); if (buffer[0x101] & 0x01) Serial.print(F("ILU ")); if (buffer[0x101] & 0x02) Serial.print(F("FLU ")); Serial.print(F("\n [0502h] PTP Status: ")); if (buffer[0x102] & 0x01) Serial.print(F("RPO ")); if (buffer[0x102] & 0x02) Serial.print(F("RPD ")); if (buffer[0x102] & 0x04) Serial.print(F("RPC ")); if (buffer[0x102] & 0x08) Serial.print(F("CPI ")); if (buffer[0x102] & 0x10) Serial.print(F("DPI ")); if (buffer[0x102] & 0x20) Serial.print(F("CIL ")); Serial.print(F("\n [0504h] Application: ")); Serial.print(buffer[0x104]); Serial.print(F("\n [0506h] WLAN: ")); if ((buffer[0x106] & 0x01) == 0x00) Serial.print(F("No Scan, ")); if ((buffer[0x106] & 0x01) == 0x01) Serial.print(F("Scanning, ")); if ((buffer[0x106] & 0x06) == 0x00) Serial.print(F("No WPS, ")); if ((buffer[0x106] & 0x06) == 0x02) Serial.print(F("WPS with PIN, ")); if ((buffer[0x106] & 0x06) == 0x04) Serial.print(F("WPS with PBC, ")); if ((buffer[0x106] & 0x08) == 0x00) Serial.print(F("Group Client, ")); if ((buffer[0x106] & 0x08) == 0x08) Serial.print(F("Group Owner ")); if ((buffer[0x106] & 0x10) == 0x00) Serial.print(F("STA, ")); if ((buffer[0x106] & 0x10) == 0x10) Serial.print(F("AP, ")); if ((buffer[0x106] & 0x60) == 0x00) Serial.print(F("Initial, ")); if ((buffer[0x106] & 0x60) == 0x20) Serial.print(F("Infrastructure, ")); if ((buffer[0x106] & 0x60) == 0x40) Serial.print(F("Wi-Fi Direct, ")); if ((buffer[0x106] & 0x80) == 0x00) Serial.print(F("No Connection, ")); if ((buffer[0x106] & 0x80) == 0x80) Serial.print(F("Connected, ")); Serial.print(F("\n [0508h] SSID: ")); for (int i = 0; i < 32 && buffer[0x108 + i] != 0; ++i) { Serial.print((char)buffer[0x108 + i]); current_ssid[i] = (char)buffer[0x108 + i]; } Serial.print(F("\n [0528h] Encryption Mode: ")); switch (buffer[0x128]) { case 0 : Serial.print(F("Open System and no encryption")); break; case 1 : Serial.print(F("Open System and WEP")); break; case 2 : Serial.print(F("Shared Key and WEP")); break; case 3 : Serial.print(F("WPA-PSK and TKIP")); break; case 4 : Serial.print(F("WPA-PSK and AES")); break; case 5 : Serial.print(F("WPA2-PSK and TKIP")); break; case 6 : Serial.print(F("WPA2-PSK and AES")); break; default: Serial.print(F("Unknown")); } Serial.print(F("\n [0529h] Signal Strength: ")); Serial.print(buffer[0x129], DEC); Serial.print(F("\n [052Ah] Channel: ")); if (buffer[0x12A] == 0) Serial.print(F("No connection")); else Serial.print(buffer[0x12A], DEC); Serial.print(F("\n [0530h] MAC Address: ")); printBytes(buffer + 0x130, 6); Serial.print(F("\n [0540h] ID: ")); for (int i = 0; i < 16 && buffer[0x140 + i] != 0; ++i) { Serial.print((char)buffer[0x140 + i]); } Serial.print(F("\n [0550h] IP Address: ")); printIPAddress(buffer + 0x150); copyIPAddress(buffer + 0x150); // IPAddressを変数にコピーする 2015,7/4 Serial.print(F("\n [0554h] Subnet Mask: ")); printIPAddress(buffer + 0x154); Serial.print(F("\n [0558h] Default Gateway: ")); printIPAddress(buffer + 0x158); Serial.print(F("\n [055Ch] Preferred DNS Server: ")); printIPAddress(buffer + 0x15C); Serial.print(F("\n [0560h] Alternate DNS Server: ")); printIPAddress(buffer + 0x160); Serial.print(F("\n [0564h] Proxy Server: ")); if ((buffer[0x164] & 0x01) == 0x00) Serial.print(F("Disabled")); if ((buffer[0x164] & 0x01) == 0x01) Serial.print(F("Enabled")); Serial.print(F("\n [0570h] Date: ")); Serial.print(buffer[0x171] + 1980, DEC); Serial.print('-'); Serial.print(buffer[0x170] >> 4, DEC); Serial.print('-'); Serial.print(buffer[0x170] & 0xF, DEC); Serial.print(F("\n [0572h] Time: ")); Serial.print(buffer[0x173] >> 3, DEC); Serial.print(':'); Serial.print(buffer[0x172] << 3 | buffer[0x170] >> 3, DEC); Serial.print(':'); Serial.print((buffer[0x172] & 0x1F) * 2, DEC); Serial.print(F("\n [0574h] HTTP Status: ")); Serial.print(buffer[0x174] & 0xEF, DEC); if ((buffer[0x174] & 0x80) == 0x00) Serial.print(F(" (No Processing)")); if ((buffer[0x174] & 0x80) == 0x80) Serial.print(F(" (Processing)")); Serial.print(F("\n [0575h] Power Save Management: ")); if ((buffer[0x175] & 0x01) == 0x00) Serial.print(F("Power Save Mode Off")); if ((buffer[0x175] & 0x01) == 0x01) Serial.print(F("Power Save Mode On")); Serial.print(F("\n [0576h] File System Management: ")); if ((buffer[0x176] & 0x01) == 0x00) Serial.print(F("FS Information may be modified")); if ((buffer[0x176] & 0x01) == 0x01) Serial.print(F("FS Information shall not be modified")); Serial.println(); return true; } boolean iSDIO_waitResponse(uint32_t sequenceId) { //Serial.print(F("\nWaiting response ")); //削除 2015,7/4 uint8_t prev = 0xFF; for (int i = 0; i < 20; ++i) { memset(buffer, 0, 0x14); // Read command response status. if (!card.readExtMemory(1, 1, 0x440, 0x14, buffer)) { return false; } uint8_t resp = get_u8(buffer + 8); if (sequenceId == get_u32(buffer + 4)) { if (prev != resp) { switch (resp) { case 0x00: //Serial.print(F("\n Initial")); //削除 2015,7/4 break; case 0x01: //Serial.print(F("\n Command Processing")); //削除 2015,7/4 break; case 0x02: //Serial.println(F("\n Command Rejected")); //削除 2015,7/4 return false; case 0x03: //Serial.println(F("\n Process Succeeded")); //削除 2015,7/4 return true; case 0x04: //Serial.println(F("\n Process Terminated")); //削除 2015,7/4 return false; default: //Serial.print(F("\n Process Failed ")); //削除 2015,7/4 //Serial.println(resp, HEX); return false; } prev = resp; } } Serial.print(F(".")); //削除 2015,7/4 delay(1000); } return false; } boolean iSDIO_disconnect(uint32_t sequenceId) { //Serial.print(F("\nDisconnect command: \n")); //削除 2015,7/4 memset(buffer, 0, 512); uint8_t* p = buffer; p = put_command_header(p, 1, 0); p = put_command_info_header(p, 0x07, sequenceId, 0); put_command_header(buffer, 1, (p - buffer)); printHex(buffer, (p - buffer)); return card.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; } boolean iSDIO_establish(uint32_t sequenceId) { //Serial.print(F("\nEstablish command: \n")); //削除 2015,7/4 memset(buffer, 0, 512); uint8_t* p = buffer; p = put_command_header(p, 1, 0); p = put_command_info_header(p, 0x03, sequenceId, 3); strcat(Establish_ssid, YourID); //Establish_ssid + YourID strcpy(Establish_ssid,NS5000); strcat(Establish_ssid,YourID); //"NS5000-YourID"を作る p = put_str_arg(p, Establish_ssid); //"sdiotest"); p = put_str_arg(p, Establish_networkKey); //"12345678"); p = put_u8_arg(p, 0x06); put_command_header(buffer, 1, (p - buffer)); printHex(buffer, (p - buffer)); return card.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; } boolean iSDIO_connect(uint32_t sequenceId, const char* ssid, const char* networkKey) { //Serial.print(F("\nConnect command: \n")); //削除 2015,7/4 memset(buffer, 0, 512); uint8_t* p = buffer; p = put_command_header(p, 1, 0); p = put_command_info_header(p, 0x02, sequenceId, 2); p = put_str_arg(p, ssid); p = put_str_arg(p, networkKey); put_command_header(buffer, 1, (p - buffer)); printHex(buffer, (p - buffer)); return card.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; } boolean iSDIO_scan(uint32_t sequenceId) { //Serial.print(F("\nScan: \n")); //削除 2015,7/4 memset(buffer, 0, 512); uint8_t* p = buffer; p = put_command_header(p, 1, 0); p = put_command_info_header(p, 0x01, sequenceId, 0); put_command_header(buffer, 1, (p - buffer)); printHex(buffer, (p - buffer)); return card.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; } boolean iSDIO_showScanResult() { // Try to output some wifi info. if (!card.readExtDataPort(1, 1, 0x200, buffer)) { return false; } uint8_t num = get_u8(buffer + 24); APs = num; //検出数を保存する。 //Serial.print(F("Number of APs: ")); // 変更する 2015,7/4 Serial.print(F("APs:")); // 変更する 2015,7/4 Serial.println(num); uint8_t* p = buffer + 28; for (int i = 0; i < num; i++){ //Serial.print(F(" ")); // 削除する 2015,7/4 Serial.print((const char*)p); Serial.print(F(",")); // 変更する 2015,7/4 printBytes(p + 32, 6); Serial.print(F(",")); // 変更する 2015,7/4 Serial.print(get_u8(p + 38), DEC); Serial.print(F(",")); // 変更する 2015,7/4 switch (get_u8(p + 39)){ case 0 : Serial.print(F("NoSec")); break; case 1 : Serial.print(F("WEP")); break; case 2 : Serial.print(F("WPA")); break; case 3 : Serial.print(F("WPA2")); break; default : Serial.print(F("error")); break; } Serial.println(); p += 44; } return true; } boolean iSDIO_http(uint32_t sequenceId) { Serial.print(F("\nhttp command: \n")); memset(buffer, 0, 512); uint8_t* p = buffer; p = put_command_header(p, 1, 0); p = put_command_info_header(p, 0x23, sequenceId, 2); p = put_str_arg(p, "flashair-developers.com"); // Argument #1. p = put_str_arg(p, // Argument #2. "GET /en/ HTTP/1.1\r\n" "Host: flashair-developers.com\r\n" "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36\r\n" "\r\n"); put_command_header(buffer, 1, (p - buffer)); printHex(buffer, (p - buffer)); return card.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; } boolean iSDIO_httpResponse() { // Read header and data. if (!card.readExtDataPort(1, 1, 0x200, buffer)) { return false; } uint32_t totalSize = get_u32(buffer + 20); uint32_t availableSize = totalSize > 488 ? 488 : totalSize; uint32_t pos = 24; for (;;) { for (uint32_t i = 0; i < availableSize; ++i) { Serial.print((char)buffer[pos + i]); } totalSize -= availableSize; // Have we read all data? if (totalSize == 0) break; // Read next data. if (!card.readExtDataPort(1, 1, 0x200, buffer)) { return false; } availableSize = totalSize > 512 ? 512 : totalSize; pos = 0; } return true; } //uint32_t nextSequenceId = 0; /* void setup() { // Initialize UART for message print. Serial.begin(9600); while (!Serial) { ; } // Initialize SD card. Serial.print(F("\nInitializing SD card...")); if (card.init(SPI_HALF_SPEED, chipSelectPin)) { Serial.print(F("OK")); } else { Serial.print(F("NG")); abort(); } // Read the previous sequence ID. if (card.readExtMemory(1, 1, 0x420, 0x34, buffer)) { if (buffer[0x20] == 0x01) { nextSequenceId = get_u32(buffer + 0x24); iSDIO_waitResponse(nextSequenceId); nextSequenceId++; } else { nextSequenceId = 0; } } else { Serial.println(F("\nFailed to read status.")); nextSequenceId = 0; } } void loop() { char ssid[16]; char networkKey[16]; if (!iSDIO_status()) { Serial.println(F("\nFailed to read status.")); } Serial.print(F("\n0. Show status")); Serial.print(F("\n1. Disconnect")); Serial.print(F("\n2. Establish")); Serial.print(F("\n3. Connect")); Serial.print(F("\n4. Scan")); Serial.print(F("\n5. HTTP Get")); Serial.print(F("\n\nCommand? (next sequence id = ")); Serial.print(nextSequenceId, DEC); Serial.println(F(")")); while (Serial.available() == 0); char command = Serial.read(); switch (command - '0') { case 0 : break; case 1 : if (iSDIO_disconnect(nextSequenceId) && iSDIO_waitResponse(nextSequenceId)) { Serial.println(F("\nSuccess.")); } else { Serial.print(F("\nFailed or waiting. errorCode=")); Serial.println(card.errorCode(), HEX); } nextSequenceId++; break; case 2 : if (iSDIO_establish(nextSequenceId) && iSDIO_waitResponse(nextSequenceId)) { Serial.println(F("\nSuccess.")); } else { Serial.print(F("\nFailed or waiting. errorCode=")); Serial.println(card.errorCode(), HEX); } nextSequenceId++; break; case 3 : Serial.print(F("SSID? ")); inputText(ssid, sizeof(ssid)); Serial.print(F("Network Key? ")); inputText(networkKey, sizeof(networkKey)); if (iSDIO_connect(nextSequenceId, ssid, networkKey) && iSDIO_waitResponse(nextSequenceId)) { Serial.println(F("\nSuccess.")); } else { Serial.print(F("\nFailed or waiting. errorCode=")); Serial.println(card.errorCode(), HEX); } nextSequenceId++; break; case 4 : if (iSDIO_scan(nextSequenceId) && iSDIO_waitResponse(nextSequenceId) && iSDIO_showScanResult()) { Serial.println(F("\nSuccess.")); } else { Serial.print(F("\nFailed or waiting. errorCode=")); Serial.println(card.errorCode(), HEX); } nextSequenceId++; break; case 5 : if (iSDIO_http(nextSequenceId) && iSDIO_waitResponse(nextSequenceId)) { iSDIO_httpResponse(); Serial.println(F("\nSuccess.")); } else { Serial.print(F("\nFailed or waiting. errorCode=")); Serial.println(card.errorCode(), HEX); } nextSequenceId++; break; default : Serial.println(F("\nUnknown command.")); break; } } */