Hi,
I am try to try out the example CONTROL LEDS OVER THE ‘NET, but get the errors below, I got BLINK AN LED to work fine.
…/SPARK_Firmware_Driver/src/hw_config.c: In function ‘LED_On’:
…/SPARK_Firmware_Driver/src/hw_config.c:505:2: warning: enumeration value ‘LED2’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:505:2: warning: enumeration value ‘LED3’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:505:2: warning: enumeration value ‘LED4’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c: In function ‘LED_Off’:
…/SPARK_Firmware_Driver/src/hw_config.c:550:2: warning: enumeration value ‘LED2’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:550:2: warning: enumeration value ‘LED3’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:550:2: warning: enumeration value ‘LED4’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c: In function ‘LED_Toggle’:
…/SPARK_Firmware_Driver/src/hw_config.c:586:2: warning: enumeration value ‘LED2’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:586:2: warning: enumeration value ‘LED3’ not handled in switch [-Wswitch]
…/SPARK_Firmware_Driver/src/hw_config.c:586:2: warning: enumeration value ‘LED4’ not handled in switch [-Wswitch]
In file included from …/CC3000_Host_Driver/nvmem.c:47:0:
…/CC3000_Host_Driver/socket.h:146:0: warning: “fd_set” redefined [enabled by default]
In file included from /opt/gcc_arm/bin/…/lib/gcc/arm-none-eabi/4.7.4/…/…/…/…/arm-none-eabi/include/stdio.h:46:0,
from …/CC3000_Host_Driver/nvmem.c:43:
/opt/gcc_arm/bin/…/lib/gcc/arm-none-eabi/4.7.4/…/…/…/…/arm-none-eabi/include/sys/types.h:234:0: note: this is the location of the previous definition
In file included from …/CC3000_Host_Driver/nvmem.c:47:0:
…/CC3000_Host_Driver/socket.h:162:0: warning: “FD_SET” redefined [enabled by default]
In file included from /opt/gcc_arm/bin/…/lib/gcc/arm-none-eabi/4.7.4/…/…/…/…/arm-none-eabi/include/stdio.h:46:0,
from …/CC3000_Host_Driver/nvmem.c:43:
Sometimes errors in other files like that can mean maybe there are missing ;'s ()'s or {}'s. If you wanted to post your code here, we could help see what’s up, or you could email me with your username at david@spark.io.
Cool, I loaded that example into the ide, this code compiled for me without issue. Is this what you have in your editor?
// -----------------------------------
// Controlling LEDs over the Internet
// -----------------------------------
// name the pins
int led1 = D0;
int led2 = D1;
// Function prototypes
int ledControl(String command);
// This routine runs only once upon reset
void setup()
{
//Register our Spark function here
Spark.function("led", ledControl);
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
// This routine loops forever
void loop()
{
// Nothing to do here
}
// This function gets called whenever there is a matching API request
// the command string format is l<led number>,<state>
// for example: l1,HIGH or l1,LOW
// l2,HIGH or l2,LOW
int ledControl(String command)
{
int state = 0;
//find out the pin number and convert the ascii to integer
int pinNumber = command.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 1) return -1;
// find out the state of the led
if(command.substring(3,7) == "HIGH") state = 1;
else if(command.substring(3,6) == "LOW") state = 0;
else return -1;
// write to the appropriate pin
digitalWrite(pinNumber, state);
return 1;
}
Ah awesome, good find! You’re totally right, {DEVICE_ID} should be your core id, something like
"0123456789abcdef01234567". You url would then be:
POST /v1/devices/0123456789abcdef01234567/led
you would need to send that request with something that can make http requests, jflasher made an example page that might make it easier to test here: http://jflasher.github.io/spark-helper/
Just a note, in the example the line
POST /v1/devices/{DEVICE_ID}/led
looks like part of the code! and its not commented.
I have now flashed the unit, sure I have the right device id and access token
but when I use the URL https://api.spark.io/v1/devices/{DEVICE_ID}/led \ -d access_token={ACCESS_TOKEN} \ -d params=l2,HIGH
get error
{
“code”: 400,
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}
Cool it looks like you’re getting responses from the server, but the server didn’t see your access token in the request. Sorry if this is a silly question, did you swap in {ACCESS_TOKEN} with the value from the build site? Click on the Settings gear on the bottom left, and then select your access token from there a pop it into the url. It’s also possible your curl request isn’t phrased as a POST request, it should look like: