Advertisement
stanleyseow

Sample Electric Imp code

Jun 20th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. ===============================================================================================
  2. Electric Imp agent side ( cloud / server side ) :-
  3. ===============================================================================================
  4.  
  5. http.onrequest(function(req, resp){
  6.     server.log("Got a HTTP request");
  7.     if (req.method == "POST"){
  8.         local body = http.urldecode(req.body)
  9.         server.log(body.data);
  10.         device.send("agentBuffers",body.data);
  11.         //device.on(recvfromImp,impBuffer);
  12.     }
  13.     resp.send(200, "<head><meta http-equiv=\"refresh\" content=\"1;url=http://stanleyseow.asuscomm.com/color/\"><html>OK</html></head>");
  14. });
  15.  
  16. ===============================================================================================
  17. Electric Imp device ( the white wifi SDcard in yr home ) :-
  18. ===============================================================================================
  19.   function watchdog2() {
  20.         agent.on("agentBuffers",function(value) {
  21.         server.log("Got a buffer from agent/http");
  22.            if ( value.len() < 33 ) {        // Make sure nRF24L01 payload is only 32bytes or less
  23.            radio.send(value,value.len());          // Send the payload to the radio
  24.            }
  25.         } );
  26.         radio.powerRX();
  27.         imp.wakeup(1, watchdog2 );    
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement