Any help would be appreciated. Thanks.
Arduino: 1.6.5 (Mac OS X), Board: "Arduino Yún"
Build options changed, rebuilding all
Using library Adafruit NeoPixel in folder: /Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel
Using library SPI in folder: /Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Using library Ethernet in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet
/Applications/Tools/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Yun" -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/variants/yun -I/Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI -I/Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet/src /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp -o /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp.o
ArduinoPixel.ino: In function 'void loop()':
ArduinoPixel.ino:185:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:196:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:203:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:212:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:216:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:221:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:70:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <Ethernet.h>
// #define DEBUG
// !!! Specify the pin and number of leds for your LED strip <====<
const int STRIP_PIN = 8;
const int NUM_OF_LEDS_ON_STRIP = 60;
// !!! Specify the MAC address and IP address for your controller <====<
// The IP address will be dependent on your local network
byte mac[] = { 0x80, 0xC2, 0x2A, 0x4E, 0x71, 0xD9 };
IPAddress ip(192, 168, 1, 100); // You may leave this as is
const int PORT = 80; // You may leave this as is
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_OF_LEDS_ON_STRIP, STRIP_PIN, NEO_GRB + NEO_KHZ800);
// Initializes an EthernetServer
// instance with port number
WiFiServer server(PORT);
WiFiClient client;
// HTTP request methods
enum Method
{
GET,
PUT
};
// Available URIs
enum Uri
{
ROOT, // "/"
STATUS, // "/strip/status/"
COLOR_GET, // "/strip/color/"
STATUS_ON, // "/strip/status/on/"
STATUS_OFF, // "/strip/status/off/"
COLOR_PUT // "/strip/color/"
};
// Specifies whether the LED strip is on or off
boolean power = false;
// Keeps the current color of the LED strip
uint8_t color[] = { 128, 128, 128 };
void setup() {
#if defined(DEBUG)
Serial.begin(9600); // Initializes the Serial port
while (!Serial) ; // Needed for Leonardo only
#endif
// Starts the Ethernet connection and the server
WiFi.begin(mac, ip);
server.begin();
#if defined(DEBUG)
Serial.print("Server is at ");
Serial.println(WiFi.localIP());
Serial.println();
#endif
// Initializes the LED strip
strip.begin();
strip.show();
}
void loop()
{
// If there is an available connection,
// it reads the request
client = server.available();
if (client) {
uint8_t i = 0;
char reqChar;
char request[35];
char buf[60];
// Reads the request line
while (client.available())
{
reqChar = client.read();
if (reqChar != '\r')
{
request[i++] = reqChar;
}
else
{
client.read(); // Gets rid of '\n'
request[i] = '\0';
break;
}
}
// Parses the request line
int8_t method, uri;
parseRequestLine(method, uri, String(request));
// Initiates the appropriate response
switch (method)
{
case GET:
switch (uri)
{
case ROOT:
respond(200, "OK", false, "Hello from Arduino Server");
break;
case STATUS:
respond(200, "OK", false, power?"ON":"OFF");
break;
case COLOR_GET:
{
String colorData = "{\"r\":" + String(color[0]) +
",\"g\":" + String(color[1]) +
",\"b\":" + String(color[2]) + "}";
respond(200, "OK", false, colorData);
}
break;
default:
respond(404, "Not Found", false, '\0');
}
break;
case PUT:
switch (uri)
{
// Turns the LED strip on
case STATUS_ON:
power = true;
colorize(color[0], color[1], color[2]);
respond(200, "OK", false, '\0');
break;
// Turn the LED strip off
case STATUS_OFF:
power = false;
colorize(0, 0, 0);
respond(200, "OK", false, '\0');
break;
// Parses the JSON data (and updates the LED strip color)
case COLOR_PUT:
getJson(buf); // Retrieves the JSON data
parseColors(String(buf)); // Parses the data
if (power)
colorize(color[0], color[1], color[2]);
respond(200, "OK", true, '\0');
break;
default:
respond(404, "Not Found", false, '\0');
}
break;
default:
respond(404, "Not Found", false, '\0');
}
}
}
// Parses the HTTP request line
// Parameters: method - the method of the request
// uri - the requested uri
// request - string that holds the request line
void parseRequestLine(int8_t& method, int8_t& uri, String request)
{
#if defined(DEBUG)
Serial.println(request);
#endif
// Parses the request method
String reqMethod = request.substring(0, 3);
if (reqMethod.equals("GET"))
method = GET;
else if (reqMethod.equals("PUT"))
method = PUT;
else
method = -1;
// Parses the URI
String reqUri = request.substring(4, request.lastIndexOf(' '));
if (reqUri.equals("/"))
uri = ROOT;
else if (reqUri.equals("/strip/status/"))
uri = STATUS;
else if (reqUri.equals("/strip/status/on/"))
uri = STATUS_ON;
else if (reqUri.equals("/strip/status/off/"))
uri = STATUS_OFF;
else if (reqUri.equals("/strip/color/"))
if (method == GET)
uri = COLOR_GET;
else
uri = COLOR_PUT;
else
uri = -1;
#if defined(DEBUG)
Serial.print("Method: ");
Serial.println(method);
Serial.print("URI: ");
Serial.println(uri);
Serial.println();
#endif
}
// Sends an HTTP response
// Parameters: statusCode - Status code for the response line
// statusMsg - Status message for the response line
// keepAlive - Whether to keep the connection open or not
// data - Data to return to client
void respond(int statusCode, const char* statusMsg, boolean keepAlive, String data)
{
#if defined(DEBUG)
Serial.print("HTTP/1.1 ");
Serial.print(statusCode);
Serial.print(" ");
Serial.println(statusMsg);
if (!keepAlive) Serial.println("Connection: close");
Serial.println();
if (data) { Serial.print(data);
Serial.println();
Serial.println(); }
#endif
client.print("HTTP/1.1 ");
client.print(statusCode);
client.print(" ");
client.println(statusMsg);
if (!keepAlive) client.println("Connection: close");
if (data) { client.println();
client.print(data); }
delay(1);
client.stop();
}
// Retrieves the JSON data
// Parameters: buf - the buffer the store the data
void getJson(char* buf)
{
uint8_t i = 0;
char prevlastCharRead = '\0';
char lastCharRead;
// Gets rid of request headers
while (client.available())
{
lastCharRead = client.read();
if (prevlastCharRead == '\r' && lastCharRead == '\n')
{
char c1 = '\0', c2 = '\0';
if (client.available()) c1 = client.read();
if (client.available()) c2 = client.read();
if (c1 == '\r' && c2 == '\n') break;
}
prevlastCharRead = lastCharRead;
}
// Retrieves the JSON data
while (client.available()) buf[i++] = client.read();
buf[i] = '\0';
#if defined(DEBUG)
Serial.println(buf);
Serial.println();
#endif
}
// Parses the colors from the JSON data
// Parameters: json - Holds the data
void parseColors(String json)
{
uint8_t idx = 0;
for (uint8_t i = 0; i < 3; ++i)
{
while (json[idx++] != ':') ;
uint8_t startIdx = idx;
while (json[idx] != ',' && json[idx] != '}') idx++;
uint8_t endIdx = idx;
String colorStr = json.substring(startIdx, endIdx);
color[i] = (uint8_t) colorStr.toInt();
}
}
// Updates the LED strip
// Parameters: r - red color value
// g - green color value
// b - blue color value
void colorize(uint8_t r, uint8_t g, uint8_t b)
{
for (uint16_t i = 0; i < strip.numPixels(); ++i)
strip.setPixelColor(i, r, g, b);
strip.show();
}
Arduino: 1.6.5 (Mac OS X), Board: "Arduino Yún"
Using library WiFi in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi
Using library Adafruit NeoPixel in folder: /Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel
Using library SPI in folder: /Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Using library Ethernet in folder: /Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet
/Applications/Tools/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Yun" -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/variants/yun -I/Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src -I/Users/craigfews/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI -I/Applications/Tools/Arduino.app/Contents/Java/libraries/Ethernet/src /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp -o /var/folders/8l/hkfn98n10gd3zfxzd6pkxg180000gn/T/build491980951959006376.tmp/ArduinoPixel.cpp.o
ArduinoPixel.ino: In function 'void setup()':
ArduinoPixel.ino:119:23: error: invalid conversion from 'byte* {aka unsigned char*}' to 'char*' [-fpermissive]
In file included from ArduinoPixel.ino:59:0:
/Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:79:9: error: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' [-fpermissive]
int begin(char* ssid, const char *passphrase);
^
ArduinoPixel.ino:119:23: error: invalid user-defined conversion from 'IPAddress' to 'const char*' [-fpermissive]
In file included from /Applications/Tools/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:30:0,
from ArduinoPixel.ino:59:
/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/IPAddress.h:50:5: note: candidate is: IPAddress::operator uint32_t() const <near match>
operator uint32_t() const { return _address.dword; };
^
/Applications/Tools/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/IPAddress.h:50:5: note: no known conversion for implicit 'this' parameter from 'uint32_t {aka long unsigned int}' to 'const char*'
ArduinoPixel.ino: In function 'void loop()':
ArduinoPixel.ino:189:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:200:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:207:55: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:216:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:220:62: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
ArduinoPixel.ino:225:54: error: converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
ArduinoPixel.ino:74:6: error: initializing argument 4 of 'void respond(int, const char*, boolean, String)'
invalid conversion from 'byte* {aka unsigned char*}' to 'char*' [-fpermissive]