2016-09-30 1 views
-1

Je veux savoir comment configurer le cloud simblee. J'ai fait un compte sur admin.simbleecloud.com. Comme j'utilise l'appareil de carte Arduino Simblee RFD22122. Ce module de carte a la possibilité d'envoyer des données au Cloud et de recevoir les données du Cloud depuis une position distante. Mais pour que le module Cloud et Board communique, je dois créer un service Cloud sous la forme d'un script PHP. Comme je suis nouveau au langage PHP. J'ai besoin de résoudre mes deux problèmes/questions ci-dessous.Service Cloud sous la forme de scripts PHP, créer une page HTML

  1. Comment puis-je créer un service de cloud sous la forme d'un script PHP pour récupérer les données que vous envoyez et l'enregistrer dans un fichier dans le format que vous choisissez (délimité par des virgules, CSV, PDF, tout format) ?

  2. Comment créer une page HTML pour accéder aux données sauvegardées par le script PHP. Vous pouvez même être en mesure de créer un travail CRON sur ce même serveur PHP pour pousser automatiquement de nouvelles données sur votre PC et tronquer le fichier.

Répondre

0

Il n'est pas nécessaire de configurer un php pour que les choses commencent à parler. Vous devez configurer l'administrateur du cloud et ensuite ajouter l'esquisse au simblee et enfin avoir une page Web qui exécute certains JS

Une promenade complète peut être trouvée à ce lien https://www.simblee.com/Simblee%20Cloud%20Reference%20v1.0.pdf J'ai copié le code pertinent ci-dessous juste en cas de rupture de lien, mais il y a aussi quelques informations utiles là-bas sur la configuration du panneau d'administration en

code pour ajouter au simblee

#include <SimbleeForMobile.h> 
#include <SimbleeForMobileClient.h> 
#include <SimbleeCloud.h> 
//SimbleeCloud ESNs 
unsigned int userID = 0xd448c367; 
unsigned int destESN = 0x00001010; 
SimbleeForMobileClient client; 
SimbleeCloud cloud(&client); 
//CONSTANTS 
int light = 3; //green led is on GPIO2 
int switchon = 5; //on switch is on GPIO5 
int switchoff = 6; //off switch is on GPIO6 
//STATE 
int prevstate = 0; 
int currentstate = 0; //0=OFF 1=ON 
//SimbleeForMobile Objects 
uint8_t mobileswitch, mobilelight, mobiletext; 
void setup() { 

pinMode(light, OUTPUT); //set light as output 
pinMode(switchon, INPUT); //set switchon as input 
pinMode(switchoff, INPUT); //set switchoff as input 
Serial.begin(9600); 
Serial.println("Light Demo Initiated"); 

Serial.print("The ESN of my light is: 0x"); 
Serial.println(cloud.myESN,HEX); 
cloud.userID = userID; 

SimbleeForMobile.advertisementData = "Light"; 
SimbleeForMobile.begin(); 
} 
void loop() { 
readswitches(); //check status of switches 
if(currentstate != prevstate){ 
checkstate(); 
prevstate = currentstate; 
} 
if(SimbleeForMobile.updatable){ 
SimbleeForMobile.updateColor(mobilelight, currentstate ? GREEN : BLACK); 
SimbleeForMobile.updateValue(mobileswitch, currentstate); 
SimbleeForMobile.updateText(mobiletext, currentstate ? "ON" : "OFF"); 
SimbleeForMobile.updateColor(mobiletext, currentstate ? BLACK : WHITE); 
SimbleeForMobile.updateX(mobiletext, currentstate ? 115 : 100); 

} 

SimbleeForMobile.process(); 
cloud.process(); 
} 
void ui(){ 
if(cloud.connect()) 
Serial.println("Cloud connected"); 
else 
Serial.println("Cloud disconnected"); 

SimbleeForMobile.beginScreen(); 
mobilelight = SimbleeForMobile.drawRect(30,80,260,260,BLACK); 
mobileswitch = SimbleeForMobile.drawSwitch(135,380); 
mobiletext = SimbleeForMobile.drawText(100,180,"OFF",WHITE,60); 
SimbleeForMobile.setEvents(mobileswitch, EVENT_PRESS); 
SimbleeForMobile.endScreen(); 
} 
void ui_event(event_t &event){ 
if(event.id == mobileswitch){ 
currentstate = !currentstate; 
} 
} 
void SimbleeCloud_onReceive(unsigned int originESN, const unsigned char *payload, int len){ 
Serial.println("Cloud Switch"); 
if(payload[0] == '1'){ 
currentstate = 1; 
} 
else if(payload[0] == '0'){ 
currentstate = 0; 
} 
else{ 
if(currentstate == 1) 
cloud.send(destESN,"1",1); 

else 
cloud.send(destESN,"0",1); 
} 
} 
void readswitches(){ 
if(digitalRead(switchon) == HIGH){ 
currentstate = 1; 
} 
if(digitalRead(switchoff) == HIGH){ 
currentstate = 0; 
} 
} 
void checkstate(){ 
if(currentstate == 1){ 
digitalWrite(light, HIGH); 
if(cloud.active()){ 
cloud.send(destESN, "1", 1); 
Serial.println("SENT"); 
} 
Serial.println("Light is ON"); 
} 
else{ 
digitalWrite(light, LOW); 
if(cloud.active()){ 
cloud.send(destESN, "0", 1); 
Serial.println("SENT"); 
} 
Serial.println("Light is OFF"); 
} 
} 
void SimbleeForMobile_onConnect(){ 
Serial.println("Mobile connected"); 
} 
void SimbleeForMobile_onDisconnect(){ 
Serial.println("Mobile disconnected"); 
Serial.println("Cloud disconnected"); 
} 
Code

pour une page web par exemple. Changez les NSE etc pour correspondre à vos paramètres du module

<style> 
body {text-align:center;} 
</style> 
<h1>Light Cloud Demo</h1> 
Cloud Status:<div id=status>Disconnected 
</div> 
Light Status:<div id=lamp>Disconnected 
</div> 
<img id="Light" 
style="padding-left:28px" 
src="https://sandbox.simblee.com/~acct1010/Images/LightOff.png" 
alt="Light Off" 
height = "400" 
width = "400"> 
<br> 
<br> 
<br> 
<button id=switchon>Light On</button> 
<button id=switchoff>Light Off</button> 
<script type="text/javascript" src="SimbleeCloud.js"></script> 
<script type="text/javascript"> 
var output = document.getElementById("status"); 
var light = document.getElementById("Light"); 
var cloud = new SimbleeCloud(); 
cloud.myESN = 0x00001010; 
cloud.userID = 0xd448c367; 
destESN = 0x75f4047a; 
cloud.connect(); 
cloud.onactive = function() { 
output.innerHTML = "Connected"; 
var payload = new ArrayBuffer(1); 
var view = new DataView(payload); 
view.setUint8(0,"2".charCodeAt(0)); 
cloud.send(destESN, payload); 
} 
cloud.oninactive = function() { 
output.innerHTML = "Disconnected"; 
} 
setInterval(function(){ 
var payload = new ArrayBuffer(1); 
var view = new DataView(payload); 
view.setUint8(0,"2".charCodeAt(0)); 
cloud.send(destESN,payload); 
},1000); 
var myVar = setInterval(function myTimer(){ 
lamp.innerHTML = "Disconnected"; 
} 
, 2000); 
document.getElementById("switchon").onclick = function() { 
var payload = new ArrayBuffer(1); 
var view = new DataView(payload); 
view.setUint8(0,"1".charCodeAt(0)); 
cloud.send(destESN, payload); 
} 
document.getElementById("switchoff").onclick = function() { 
var payload = new ArrayBuffer(1); 
var view = new DataView(payload); 
view.setUint8(0,"0".charCodeAt(0)); 
cloud.send(destESN, payload); 
} 
cloud.onrequest = function(originESN,payload){ 
window.clearInterval(myVar); 
myVar = setInterval(function myTimer(){ 
lamp.innerHTML = "Disconnected"; 
},1500); 
var view = new DataView(payload); 
var data = String.fromCharCode(view.getUint8(0)); 
lamp.innerHTML = "Connected"; 
if(data == '1'){ 
light.src = "https://sandbox.simblee.com/~acct1010/Images/LightOn.png"; 
} 
else if(data =='0'){ 
light.src = "https://sandbox.simblee.com/~acct1010/Images/LightOff.png"; 
} 
} 
</script> 

et enfin simblee.js ressemble à ce

/* 
* Copyright (c) 2015 RF Digital Corp. All Rights Reserved. 
* 
* The source code contained in this file and all intellectual property embodied in 
* or covering the source code is the property of RF Digital Corp. or its licensors. 
* Your right to use this source code and intellectual property is non-transferable, 
* non-sub licensable, revocable, and subject to terms and conditions of the 
* SIMBLEE SOFTWARE LICENSE AGREEMENT. 
* http://www.simblee.com/licenses/SimbleeSoftwareLicenseAgreement.txt 
* 
* THE SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. 
* 
* This heading must NOT be removed from this file. 
*/ 

SimbleeCloud = function(esn, userid) { 
    this.myESN = esn || 0x00000000; 
    this.userID = userid || 0x00000000; 

    this.assignedESN = null; 

    this.active = false; 

    this.onactive = null; 
    this.oninactive = null; 
    this.oninitial = null; 
    this.onrequest = null; 
    this.oncountresult = null; 
}; 

SimbleeCloud.prototype = {}; 

SimbleeCloud.MAX_MODULE_PAYLOAD = 180; 

SimbleeCloud.LITTLE_ENDIAN = true; 

SimbleeCloud.MCS_FUNCTION_CALL = 0xffffffff; 

SimbleeCloud.MCS_FUNCTION_NONE = 0; 
SimbleeCloud.MCS_FUNCTION_PING = 1; 
SimbleeCloud.MCS_FUNCTION_PONG = 2; 
SimbleeCloud.MCS_FUNCTION_COUNT = 3; 
SimbleeCloud.MCS_FUNCTION_INITIAL = 4; 

/* 
SimbleeCloud.prototype._var = false; 
Object.defineProperty(SimbleeCloud.prototype, 'var', 
    { get: function() { 
     return this._var; 
    }, 
    set: function(v) { 
     this._var = v; 
    } }); 
*/ 

SimbleeCloud.prototype.copyBytes = function(target, source, targetOffset, sourceOffset, length) { 
    targetOffset = targetOffset || 0; 
    sourceOffset = sourceOffset || 0; 
    length = length || source.byteLength; 

    var view = new Uint8Array(target, targetOffset); 
    view.set(new Uint8Array(source, sourceOffset, length)); 
}; 

SimbleeCloud.prototype.send = function(destESN, payload) { 
    var len = payload.byteLength; 

    if (len > SimbleeCloud.MAX_MODULE_PAYLOAD) 
    len = SimbleeCloud.MAX_MODULE_PAYLOAD; 

    var msg_len = 1 + 4 + len; 

    var buffer = new ArrayBuffer(1 + 4 + len); 
    var view = new DataView(buffer); 
    view.setUint8(0, 1 + 4 + len); 
    view.setUint32(1, destESN, SimbleeCloud.LITTLE_ENDIAN); 
    this.copyBytes(buffer, payload, 5, 0, len); 

    this.websocket.send(buffer); 
}; 

SimbleeCloud.prototype.onwebsocketopen = function() { 
    // "this" is the websocket, not the SimbleeCloud object 
    var self = this.outer; 

    // start byte 
    self.websocket.send("!"); 

    // start message (my esn, then user id for authorization) 
    var payload = new ArrayBuffer(4); 
    var view = new DataView(payload); 
    view.setUint32(0, self.userID, SimbleeCloud.LITTLE_ENDIAN); 
    self.send(self.myESN, payload); 
}; 

SimbleeCloud.prototype.countasync = function(esn) { 
    var payload = new ArrayBuffer(5); 
    var view = new DataView(payload); 
    view.setUint8(0, SimbleeCloud.MCS_FUNCTION_COUNT); 
    view.setUint32(1, esn, SimbleeCloud.LITTLE_ENDIAN); 
    this.send(SimbleeCloud.MCS_FUNCTION_CALL, payload); 
}; 

SimbleeCloud.prototype.onmcsfunctioncall = function(requestBuffer) { 
    var requestView = new DataView(requestBuffer); 

    var funct = requestView.getUint8(5); 

    if (funct == SimbleeCloud.MCS_FUNCTION_PING) 
    { 
    // console.log("ping"); 
    // send pong (retaining conv area) 
    var responseBuffer = requestBuffer.slice(0); 
    var responseView = new DataView(responseBuffer); 
    responseView.setUint8(5, SimbleeCloud.MCS_FUNCTION_PONG); 
    this.websocket.send(responseBuffer); 
    } 
    else if (funct == SimbleeCloud.MCS_FUNCTION_PONG) 
    { 
    // process pong 
    } 
    else if (funct == SimbleeCloud.MCS_FUNCTION_COUNT) 
    { 
    // process count result 
    var result = requestView.getUint32(6, true); 
    if (this.oncountresult) 
     this.oncountresult(result); 
    } 
    else if (funct == SimbleeCloud.MCS_FUNCTION_INITIAL) 
    { 
    // process initial 
    var esn = requestView.getUint32(6, true); 
    if (this.oninitial) 
     this.oninitial(esn); 
    } 

    // ignore unknown mcs function calls 
}; 

SimbleeCloud.prototype.onprocess = function(buffer) { 
    var view = new DataView(buffer); 

    var len = view.getUint8(0); 
    var originESN = view.getUint32(1, true); 

    // pool response 
    if (originESN == this.myESN) { 
    this.assignedESN = view.getUint32(5, true); 
    // console.log("assignedESN = 0x" + this.assignedESN.toString(16)); 
    } 

    if (! this.active) { 
    this.active = true; 
    if (this.onactive) 
     this.onactive(); 
    } 

    // pool response 
    if (originESN == this.myESN) 
    return; 

    if (originESN == SimbleeCloud.MCS_FUNCTION_CALL) { 
    this.onmcsfunctioncall(buffer); 
    return; 
    } 

    if (this.onrequest) { 
    var payload = buffer.slice(5); 
    this.onrequest(originESN, payload); 
    } 
}; 

SimbleeCloud.prototype.onwebsocketmessage = function(evt) { 
    // "this" is the websocket, not the SimbleeCloud object 
    var self = this.outer; 

    var fileReader = new FileReader(); 

    fileReader.onload = function() { 
    self.onprocess(this.result); 
    }; 

    fileReader.readAsArrayBuffer(evt.data); 
}; 

SimbleeCloud.prototype.onwebsocketerror = function(evt) { 
    var code = evt.code; 

    // "this" is the websocket, not the SimbleeCloud object 
    var self = this.outer; 
}; 

SimbleeCloud.prototype.onwebsocketclose = function(evt) { 
    var code = evt.code; 

    // See http://tools.ietf.org/html/rfc6455#section-7.4.1 
    var reason; 
    if (code == 1000) 
    reason = "Normal closure, meaning that the purpose for which the connection was established has been fulfilled."; 
    else if(code == 1001) 
    reason = "An endpoint is \"going away\", such as a server going down or a browser having navigated away from a page."; 
    else if(code == 1002) 
    reason = "An endpoint is terminating the connection due to a protocol error"; 
    else if(code == 1003) 
    reason = "An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message)."; 
    else if(code == 1004) 
    reason = "Reserved. The specific meaning might be defined in the future."; 
    else if(code == 1005) 
    reason = "No status code was actually present."; 
    else if(code == 1006) 
    reason = "The connection was closed abnormally, e.g., without sending or receiving a Close control frame"; 
    else if(code == 1007) 
    reason = "An endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [http://tools.ietf.org/html/rfc3629] data within a text message)."; 
    else if(code == 1008) 
    reason = "An endpoint is terminating the connection because it has received a message that \"violates its policy\". This reason is given either if there is no other sutible reason, or if there is a need to hide specific details about the policy."; 
    else if(code == 1009) 
    reason = "An endpoint is terminating the connection because it has received a message that is too big for it to process."; 
    else if(code == 1010) // Note that this status code is not used by the server, because it can fail the WebSocket handshake instead. 
    reason = "An endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. <br /> Specifically, the extensions that are needed are: " + event.reason; 
    else if(code == 1011) 
    reason = "A server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."; 
    else if(code == 1015) 
    reason = "The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."; 
    else 
    reason = "Unknown reason"; 

    // console.log("onwebsocketclose: " + code + " - " + reason); 

    // "this" is the websocket, not the SimbleeCloud object 
    var self = this.outer; 

    if (self.active) { 
    self.active = false; 
    if (self.oninactive) 
     self.oninactive(); 
    } 
}; 

SimbleeCloud.prototype.connect = function() { 
    try 
    { 
    this.websocket = new WebSocket("wss://connect.simbleecloud.com:443"); 

    this.websocket.outer = this; 

    this.websocket.onopen = this.onwebsocketopen; 
    this.websocket.onmessage = this.onwebsocketmessage; 
    this.websocket.onerror = this.onwebsocketerror; 
    this.websocket.onclose = this.onwebsocketclose; 
    } 
    catch(e) 
    { 
    console.log(e); 
    } 
}; 

Dans le code que vous pouvez télécharger à partir du lien dans ce pdf, vous pouvez obtenir quelques exemples php mais ce n'est pas nécessaire pour cet exemple de base