├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── CC3000_MDNS.cpp ├── CC3000_MDNS.h ├── README.md ├── examples └── MDNS_Echo_Server │ └── MDNS_Echo_Server.ino └── library.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /CC3000_MDNS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | CC3000 Multicast DNS 4 | Version 1.1 5 | Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) 6 | 7 | License (MIT license): 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | */ 27 | 28 | // Important RFC's for reference: 29 | // - DNS request and response: http://www.ietf.org/rfc/rfc1035.txt 30 | // - Multicast DNS: http://www.ietf.org/rfc/rfc6762.txt 31 | 32 | #include "CC3000_MDNS.h" 33 | 34 | #define READ_BUFFER_SIZE 20 35 | #define HEADER_SIZE 12 36 | #define QDCOUNT_OFFSET 4 37 | #define A_RECORD_SIZE 14 38 | #define NSEC_RECORD_SIZE 20 39 | #define TTL_OFFSET 4 40 | #define IP_OFFSET 10 41 | 42 | int MDNSResponder::_mdnsSocket = -1; 43 | 44 | MDNSResponder::MDNSResponder() 45 | : _expected(NULL) 46 | , _expectedLen(0) 47 | , _response(NULL) 48 | , _responseLen(0) 49 | , _index(0) 50 | { } 51 | 52 | MDNSResponder::~MDNSResponder() { 53 | if (_expected != NULL) { 54 | free(_expected); 55 | } 56 | if (_response != NULL) { 57 | free(_response); 58 | } 59 | } 60 | 61 | bool MDNSResponder::begin(const char* domain, Adafruit_CC3000& cc3000, uint32_t ttlSeconds) 62 | { 63 | // Call gethostbyname on localhost as suggested by TI to deal with firmware v1.13 issue: 64 | // http://e2e.ti.com/support/wireless_connectivity/f/851/t/342177.aspx 65 | // See issue #1 on github repository for more details. 66 | uint32_t output; 67 | int result = gethostbyname("localhost", 9, &output); 68 | 69 | // Construct DNS request/response fully qualified domain name of form: 70 | // , , 5, "local" 71 | size_t n = strlen(domain); 72 | if (n > 255) { 73 | // Can only handle domains that are 255 chars in length. 74 | return false; 75 | } 76 | _expectedLen = 12 + n; 77 | if (_expected != NULL) { 78 | free(_expected); 79 | } 80 | _expected = (uint8_t*) malloc(_expectedLen); 81 | if (_expected == NULL) { 82 | return false; 83 | } 84 | _expected[0] = (uint8_t)n; 85 | // Copy in domain characters as lowercase 86 | for (int i = 0; i < n; ++i) { 87 | _expected[1+i] = tolower(domain[i]); 88 | } 89 | // Values for: 90 | // - 5 (length) 91 | // - "local" 92 | // - 0x00 (end of domain) 93 | // - 0x00 0x01 (A record query) 94 | // - 0x00 0x01 (Class IN) 95 | uint8_t local[] = { 0x05, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0x01, 0x00, 0x01 }; 96 | memcpy(&_expected[1+n], local, 11); 97 | 98 | // Construct DNS query response 99 | // TODO: Move these to flash or just construct in code. 100 | uint8_t respHeader[] = { 0x00, 0x00, // ID = 0 101 | 0x84, 0x00, // Flags = response + authoritative answer 102 | 0x00, 0x00, // Question count = 0 103 | 0x00, 0x01, // Answer count = 1 104 | 0x00, 0x00, // Name server records = 0 105 | 0x00, 0x01 // Additional records = 1 106 | }; 107 | // Generate positive response for IPV4 address 108 | uint8_t aRecord[] = { 0x00, 0x01, // Type = 1, A record/IPV4 address 109 | 0x80, 0x01, // Class = Internet, with cache flush bit 110 | 0x00, 0x00, 0x00, 0x00, // TTL in seconds, to be filled in later 111 | 0x00, 0x04, // Length of record 112 | 0x00, 0x00, 0x00, 0x00 // IP address, to be filled in later 113 | }; 114 | // Generate negative response for IPV6 address (CC3000 doesn't support IPV6) 115 | uint8_t nsecRecord[] = { 0xC0, 0x0C, // Name offset 116 | 0x00, 0x2F, // Type = 47, NSEC (overloaded by MDNS) 117 | 0x80, 0x01, // Class = Internet, with cache flush bit 118 | 0x00, 0x00, 0x00, 0x00, // TTL in seconds, to be filled in later 119 | 0x00, 0x08, // Length of record 120 | 0xC0, 0x0C, // Next domain = offset to FQDN 121 | 0x00, // Block number = 0 122 | 0x04, // Length of bitmap = 4 bytes 123 | 0x40, 0x00, 0x00, 0x00 // Bitmap value = Only first bit (A record/IPV4) is set 124 | }; 125 | // Allocate memory for response. 126 | int queryFQDNLen = _expectedLen - 4; 127 | _responseLen = HEADER_SIZE + queryFQDNLen + A_RECORD_SIZE + NSEC_RECORD_SIZE; 128 | if (_response != NULL) { 129 | free(_response); 130 | } 131 | _response = (uint8_t*) malloc(_responseLen); 132 | if (_response == NULL) { 133 | return false; 134 | } 135 | // Copy data into response. 136 | memcpy(_response, respHeader, HEADER_SIZE); 137 | memcpy(_response + HEADER_SIZE, _expected, queryFQDNLen); 138 | uint8_t* records = _response + HEADER_SIZE + queryFQDNLen; 139 | memcpy(records, aRecord, A_RECORD_SIZE); 140 | memcpy(records + A_RECORD_SIZE, nsecRecord, NSEC_RECORD_SIZE); 141 | // Add TTL to records. 142 | uint8_t ttl[4] = { (uint8_t)(ttlSeconds >> 24), (uint8_t)(ttlSeconds >> 16), (uint8_t)(ttlSeconds >> 8), (uint8_t)ttlSeconds }; 143 | memcpy(records + TTL_OFFSET, ttl, 4); 144 | memcpy(records + A_RECORD_SIZE + 2 + TTL_OFFSET, ttl, 4); 145 | // Add IP address to response 146 | uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; 147 | if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) 148 | { 149 | return false; 150 | } 151 | records[IP_OFFSET] = (uint8_t)(ipAddress >> 24); 152 | records[IP_OFFSET + 1] = (uint8_t)(ipAddress >> 16); 153 | records[IP_OFFSET + 2] = (uint8_t)(ipAddress >> 8); 154 | records[IP_OFFSET + 3] = (uint8_t) ipAddress; 155 | 156 | // Open the MDNS socket if it isn't already open. 157 | if (_mdnsSocket == -1) { 158 | // Create the UDP socket 159 | int soc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 160 | if (soc < 0) { 161 | return false; 162 | } 163 | // Use port 5353 and listen/send to the multicast IP 224.0.0.251 164 | sockaddr_in address; 165 | memset(&address, 0, sizeof(address)); 166 | address.sin_family = AF_INET; 167 | address.sin_port = htons(5353); 168 | address.sin_addr.s_addr = htonl(cc3000.IP2U32(224, 0, 0, 251)); 169 | socklen_t len = sizeof(address); 170 | if (bind(soc, (sockaddr*) &address, sizeof(address)) < 0) { 171 | return false; 172 | } 173 | _mdnsSocket = soc; 174 | } 175 | 176 | return true; 177 | } 178 | 179 | void MDNSResponder::update() { 180 | // Check if data is available to read using select 181 | timeval timeout; 182 | timeout.tv_sec = 0; 183 | timeout.tv_usec = 5000; 184 | fd_set reads; 185 | FD_ZERO(&reads); 186 | FD_SET(_mdnsSocket, &reads); 187 | select(_mdnsSocket + 1, &reads, NULL, NULL, &timeout); 188 | if (!FD_ISSET(_mdnsSocket, &reads)) { 189 | // No data to read. 190 | return; 191 | } 192 | // Read available data. 193 | uint8_t buffer[READ_BUFFER_SIZE]; 194 | int n = recv(_mdnsSocket, &buffer, sizeof(buffer), 0); 195 | if (n < 1) { 196 | // Error getting data. 197 | return; 198 | } 199 | // Look for domain name in request and respond with canned response if found. 200 | for (int i = 0; i < n; ++i) { 201 | uint8_t ch = tolower(buffer[i]); 202 | // Check character matches expected. 203 | if (ch == _expected[_index]) 204 | { 205 | _index++; 206 | // Check if domain name was found and send a response. 207 | if (_index >= _expectedLen) { 208 | // Send response to multicast address. 209 | send(_mdnsSocket, _response, _responseLen, 0); 210 | _index = 0; 211 | } 212 | } 213 | else if (ch == _expected[0]) { 214 | // Found a character that doesn't match, but does match the start of the domain. 215 | _index = 1; 216 | } 217 | else { 218 | // Found a character that doesn't match the expected character or start of domain. 219 | _index = 0; 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /CC3000_MDNS.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | CC3000 Multicast DNS 4 | Version 1.1 5 | Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) 6 | 7 | This is a simple implementation of multicast DNS query support for an Arduino 8 | and CC3000 WiFI chip. Only support for resolving address queries is currently 9 | implemented. 10 | 11 | Requirements: 12 | - Adafruit CC3000 Library: https://github.com/adafruit/Adafruit_CC3000_Library 13 | 14 | Usage: 15 | - Include the CC3000 Multicast DNS library in the sketch. 16 | - Create an instance of the MDNSResponder class. 17 | - Call the begin method in the sketch's setup and provide a domain name (without 18 | the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'), and the 19 | Adafruit CC3000 class instance. Optionally provide a time to live (in seconds) 20 | for the DNS record--the default is 1 hour. 21 | - Call the update method in each iteration of the sketch's loop function. 22 | 23 | License (MIT license): 24 | Permission is hereby granted, free of charge, to any person obtaining a copy 25 | of this software and associated documentation files (the "Software"), to deal 26 | in the Software without restriction, including without limitation the rights 27 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | copies of the Software, and to permit persons to whom the Software is 29 | furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice shall be included in 32 | all copies or substantial portions of the Software. 33 | 34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | THE SOFTWARE. 41 | 42 | */ 43 | #ifndef CC3000_MDNS_H 44 | #define CC3000_MDNS_H 45 | 46 | #include "Adafruit_CC3000.h" 47 | #include "utility/socket.h" 48 | 49 | class MDNSResponder { 50 | public: 51 | MDNSResponder(); 52 | ~MDNSResponder(); 53 | bool begin(const char* domain, Adafruit_CC3000& cc3000, uint32_t ttlSeconds = 3600); 54 | void update(); 55 | 56 | private: 57 | // Expected query values 58 | static uint8_t _queryHeader[]; 59 | uint8_t* _expected; 60 | int _expectedLen; 61 | // Current parsing state 62 | int _index; 63 | // Response data 64 | uint8_t* _response; 65 | int _responseLen; 66 | // Socket for MDNS communication 67 | static int _mdnsSocket; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This example is deprecated, we no longer make/support CC3000! 2 | 3 | CC3000 Multicast DNS 4 | ==================== 5 | 6 | Version 1.1 7 | 8 | This is a simple implementation of multicast DNS query support for an Arduino 9 | and CC3000 WiFI chip. Only support for resolving address queries is currently 10 | implemented. 11 | 12 | Requirements 13 | ------------ 14 | - [Adafruit CC3000 Library](https://github.com/adafruit/Adafruit_CC3000_Library) 15 | - MDNS support in your operating system/client machines: 16 | - For Mac OSX support is built in through Bonjour already. 17 | - For Linux, install [Avahi](http://avahi.org/). 18 | - For Windows, install [Bonjour](http://www.apple.com/support/bonjour/). 19 | 20 | Usage 21 | ----- 22 | 1. Download this repository as a zip (button on the right) and follow [these instructions to install into Arduino](http://arduino.cc/en/Guide/Libraries). 23 | 2. Include the CC3000 Multicast DNS library in the sketch. 24 | 3. Create an instance of the MDNSResponder class. 25 | 4. Call the begin method in the sketch's setup and provide a domain name (without 26 | the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'), and the 27 | Adafruit CC3000 class instance. Optionally provide a time to live (in seconds) 28 | for the DNS record--the default is 1 hour. 29 | 5. Call the update method in each iteration of the sketch's loop function. 30 | 31 | See the included MDNS echo server example for a full example (make sure you have the latest 32 | version of Adafruit's CC3000 library with server support). 33 | 34 | License 35 | ------- 36 | Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy 39 | of this software and associated documentation files (the "Software"), to deal 40 | in the Software without restriction, including without limitation the rights 41 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | copies of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in 46 | all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | THE SOFTWARE. 55 | -------------------------------------------------------------------------------- /examples/MDNS_Echo_Server/MDNS_Echo_Server.ino: -------------------------------------------------------------------------------- 1 | 2 | /*************************************************** 3 | Adafruit CC3000 Multicast DNS Echo Server 4 | 5 | This is a simple example of an echo server that responds 6 | to multicast DNS queries on the 'cc3kserver.local' address. 7 | 8 | See the CC3000 tutorial on Adafruit's learning system 9 | for more information on setting up and using the 10 | CC3000: 11 | http://learn.adafruit.com/adafruit-cc3000-wifi 12 | 13 | Requirements: 14 | 15 | This sketch requires the Adafruit CC3000 library. You can 16 | download the library from: 17 | https://github.com/adafruit/Adafruit_CC3000_Library 18 | 19 | For information on installing libraries in the Arduino IDE 20 | see this page: 21 | http://arduino.cc/en/Guide/Libraries 22 | 23 | You must also have MDNS/Bonjour support installed on machines 24 | that will try to access the server: 25 | - For Mac OSX support is available natively in the operating 26 | system. 27 | - For Linux, install Avahi: http://avahi.org/ 28 | - For Windows, install Bonjour: http://www.apple.com/support/bonjour/ 29 | 30 | Usage: 31 | 32 | Update the SSID and, if necessary, the CC3000 hardware pin 33 | information below, then run the sketch and check the 34 | output of the serial port. Once listening for connections, 35 | connect to the server from your computer using a telnet 36 | client on port 7. 37 | 38 | For example on Linux or Mac OSX, if your CC3000 has an 39 | IP address 192.168.1.100 you would execute in a command 40 | window: 41 | 42 | telnet cc3kserver.local 7 43 | 44 | After connecting, notice that as you type input and 45 | press enter to send it the CC3000 will echo back exactly 46 | what you typed. Press ctrl-] and type quit at the prompt 47 | to close the telnet session. 48 | 49 | On Windows you'll need to download a telnet client. PuTTY 50 | is a good, free GUI client: 51 | http://www.chiark.greenend.org.uk/~sgtatham/putty/ 52 | 53 | License: 54 | 55 | This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com) 56 | and is released under an open source MIT license. See details at: 57 | http://opensource.org/licenses/MIT 58 | 59 | This code was adapted from Adafruit CC3000 library example 60 | code which has the following license: 61 | 62 | Designed specifically to work with the Adafruit WiFi products: 63 | ----> https://www.adafruit.com/products/1469 64 | 65 | Adafruit invests time and resources providing this open source code, 66 | please support Adafruit and open-source hardware by purchasing 67 | products from Adafruit! 68 | 69 | Written by Limor Fried & Kevin Townsend for Adafruit Industries. 70 | BSD license, all text above must be included in any redistribution 71 | ****************************************************/ 72 | #include 73 | #include 74 | #include 75 | 76 | // These are the interrupt and control pins 77 | #define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! 78 | // These can be any two pins 79 | #define ADAFRUIT_CC3000_VBAT 5 80 | #define ADAFRUIT_CC3000_CS 10 81 | // Use hardware SPI for the remaining pins 82 | // On an UNO, SCK = 13, MISO = 12, and MOSI = 11 83 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, 84 | SPI_CLOCK_DIV2); // you can change this clock speed 85 | 86 | #define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! 87 | #define WLAN_PASS "myPassword" 88 | // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 89 | #define WLAN_SECURITY WLAN_SEC_WPA2 90 | 91 | #define LISTEN_PORT 7 // What TCP port to listen on for connections. 92 | 93 | Adafruit_CC3000_Server echoServer(LISTEN_PORT); 94 | 95 | MDNSResponder mdns; 96 | 97 | void setup(void) 98 | { 99 | Serial.begin(115200); 100 | Serial.println(F("Hello, CC3000!\n")); 101 | 102 | // Set up CC3000 and get connected to the wireless network. 103 | Serial.println(F("\nInitializing...")); 104 | if (!cc3000.begin()) 105 | { 106 | Serial.println(F("Couldn't begin()! Check your wiring?")); 107 | while(1); 108 | } 109 | if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { 110 | Serial.println(F("Failed!")); 111 | while(1); 112 | } 113 | while (!cc3000.checkDHCP()) 114 | { 115 | delay(100); 116 | } 117 | Serial.println(); 118 | 119 | // Start multicast DNS responder 120 | if (!mdns.begin("cc3kserver", cc3000)) { 121 | Serial.println(F("Error setting up MDNS responder!")); 122 | while(1); 123 | } 124 | 125 | // Start server 126 | echoServer.begin(); 127 | 128 | Serial.println(F("Listening for connections...")); 129 | } 130 | 131 | void loop(void) 132 | { 133 | // Handle any multicast DNS requests 134 | mdns.update(); 135 | 136 | // Handle any connected clients 137 | Adafruit_CC3000_ClientRef client = echoServer.available(); 138 | if (client) { 139 | // Check if there is data available to read and echo it back. 140 | if (client.available() > 0) { 141 | uint8_t ch = client.read(); 142 | client.write(ch); 143 | } 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=CC3000 MDNS 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Simple multicast DNS name resolution library for Adafruit's CC3000 and Arduino. 6 | paragraph=Simple multicast DNS name resolution library for Adafruit's CC3000 and Arduino. 7 | category=Communication 8 | url=https://github.com/adafruit/CC3000_MDNS 9 | architectures=* 10 | --------------------------------------------------------------------------------