| Electronic Components Datasheet Search |
|
DEV-12887 Datasheet(PDF) 28 Page - SparkFun Electronics |
|
|
|||||||||||||||||||||||||||||
DEV-12887 Datasheet(HTML) 28 Page - SparkFun Electronics |
|
28 / 40 page ![]() else if ((colorNibble >= 'a') && (colorNibble <= 'f')) { return colorNibble 87; } else if ((colorNibble >= 'A') && (colorNibble <= 'F')) { return colorNibble 55; } } Check out the comments in the code for a line-by-line dissection. Most of the code on the agent is an HTTP request handler (the requestHandler(request, response) function). This function uses a series of if statements to check for a specific request parameter key (like “led” or “rgb”). In those if statements, the agent decides what to do with the parameter value (if anything) and sends a message to the imp using the device.send function. With both of those halves of code added to your model, and the circuit built, build and run the model. Time to test it out! Testing the Model After initially running the model, you shouldn’t see anything happen to your imp or the LEDs it’s connected to. To change that, we need to send an HTTP request to the agent. First, we need to locate the URL of our agent, which is printed at the top of your Agent window. It’ll be something like https://agent.electricimp.com/0123456789ABCDEF . Each imp gets its own, unique, agent URL. How to locate the agent URL. Mine, for example, is https://agent.electricimp.com/UpyYpRLmBB7m. We can send requests to the agent by adding URL query strings onto the agent URL. For example, type https://agent.electricimp.com/qJx35x_LTITP?led=1 (make sure you replace my unique code with your own!) into your browser’s address bar and go. Notice anything happen on your imp circuit? The lonely red LED should have turned on! Look through the agent code to see what other parameters we can send. We can even add multiple parameters to the same request, for example try going to https://agent.electricimp.com/qJx35x_LTITP?led=1&rgb=%234080ff&timer=10 in your browser. This request turns on the LED, but it also sends an RGB string to control the RGB LED and it sets a timer to turn all LEDs off. This is very cool, but typing these parameters into an address bar is a pain! Let’s write a simple HTML webpage to take a form input and do all of that for us! The HTML Code This is the last piece to the puzzle – a simple HTML page that takes a form input, and sends that information out to our Electric Imp agent. Create a local file on your computer called impControl.html. Open it with a text editor, and paste the below code into it.: Page 28 of 40 |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |