Electronic Components Datasheet Search
  English  ▼

X  

DEV-12887 Datasheet(PDF) 35 Page - SparkFun Electronics

Part # DEV-12887
Description  Electric Imp Breakout Hookup Guide
PDF  40 Pages
Scroll/Zoom Zoom In 100%  Zoom Out
Manufacturer  SPARKFUN [SparkFun Electronics]
Direct Link  https://www.sparkfun.com/
Logo SPARKFUN - SparkFun Electronics

DEV-12887 Datasheet(HTML) 35 Page - SparkFun Electronics

Back Button DEV-12887 Datasheet HTML 31Page - SparkFun Electronics DEV-12887 Datasheet HTML 32Page - SparkFun Electronics DEV-12887 Datasheet HTML 33Page - SparkFun Electronics DEV-12887 Datasheet HTML 34Page - SparkFun Electronics DEV-12887 Datasheet HTML 35Page - SparkFun Electronics DEV-12887 Datasheet HTML 36Page - SparkFun Electronics DEV-12887 Datasheet HTML 37Page - SparkFun Electronics DEV-12887 Datasheet HTML 38Page - SparkFun Electronics DEV-12887 Datasheet HTML 39Page - SparkFun Electronics Next Button
Zoom Inzoom in Zoom Outzoom out
 35 / 40 page
background image
s/api/http/jsonencode/
    local jvars = http.jsonencode(pinTable);
// Attach a header to our response.
// "Access­Control­Allow­Origin: *" allows cross­origin re
source sharing
// https://electricimp.com/docs/api/httpresponse/header/
    response.header("Access­Control­Allow­Origin", "*");
// Send out our response. 
// 200 is the "OK" http status code
// jvars is our response string. The JSON table we constru
cted earlier.
// https://electricimp.com/docs/api/httpresponse/send/
    response.send(200,jvars);
} 
// device.on("impValues") will be called whenever an "impValue
s" request is sent
// from the device side. This simple function simply fills up 
our global variables
// with the equivalent vars received from the imp.
device.on("impValues", function(iv) {
    _pin1 = iv.pin1;
    _pin2 = iv.pin2;
    _pin5 = iv.pin5;
    _pin7 = iv.pin7;
    _pin8 = iv.pin8;
    _pin9 = iv.pin9;
    _voltage = iv.voltage;
    }); 
///////////
// Setup //
///////////
// http.onrequest(function) sets up a function handler to cal
l when an http
// request is received. Whenever we receive an http request ca
ll respondImpValues
// https://electricimp.com/docs/api/http/onrequest/
http.onrequest(respondImpValues);
There are two things to point out here. The first is the device.on function.
This function sets up a handler to be called when the imp sends a defined
string. In this case, we’re looking for the imp sending “impValues”. The data
associated with this string is a table, full of all of the imp’s pin readings.
That function is called every time the imp sends that specific string to the
agent.
The real magic happens in the respondImpValues() function. The agent
sets this function as the handler for any HTTP request (using the
http.onrequest function). This function constructs a JSON string of data,
in the form of “"key”:“value”, “key”:“value”, …,“, which the requesting HTTP
client should be able to parse and understand.
Check the comments in the code for more information on the agent code.
For now, Build and Run the code. Don’t expect it to do anything of interest
until we add the last bit of magic…
The Web App – AJAX, jQuery, JSON Oh My!
The final piece to this puzzle is constructing a web page that can both send
an HTTP request and deal with the response from the agent.
Page 35 of 40



Html Pages

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40


Datasheet Download

Go To PDF Page


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


Mirror Sites
English : Alldatasheet.com  |   English : Alldatasheet.net  |   Chinese : Alldatasheetcn.com  |   German : Alldatasheetde.com  |   Japanese : Alldatasheet.jp
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