Облачный сервис в виде скриптов PhP, создающий HTML-страницу

Я хочу знать, как мне настроить simblee cloud. Я сделал учетную запись на admin.simbleecloud.com. В качестве устройства я использую плату Arduino Simblee RFD22122. Этот модуль платы имеет возможность отправлять данные в облако и получать данные из облака из удаленного пункта. Но для взаимодействия модуля Cloud и Board я должен создать облачный сервис в виде сценария PHP. Как я новичок в языке PHP. Мне нужно решить мои ниже две проблемы / вопросы.

  1. Как создать облачный сервис в виде PHP-скрипта для извлечения отправляемых вами данных и сохранения их в файл в любом формате, который вы выберете (с разделителями-запятыми, CSV, PDF, в любом формате).?

  2. Как создать HTML-страницу для доступа к данным, сохраненным сценарием PHP. Возможно, вам даже удастся создать задание CRON на том же PHP-сервере, чтобы автоматически передавать любые новые данные на ваш ПК и обрезать файл.

-1

Решение

Нет необходимости настраивать php для начала разговора. Вам нужно настроить облачного администратора, а затем добавить эскиз к simblee и, наконец, создать веб-страницу с JS

Полный путь можно найти по этой ссылке https://www.simblee.com/Simblee%20Cloud%20Reference%20v1.0.pdf Я скопировал и вставил соответствующий код ниже на случай, если ссылка не работает, но там также есть некоторая полезная информация по настройке панели администратора.

код для добавления в 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");
}

код для примера веб-страницы. Измените ESN и т. Д. В соответствии с настройками вашего модуля

<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>

и, наконец, simblee.js выглядит так

/*
* 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);
}
};

В коде, который вы можете скачать по ссылке в этом PDF-файле, вы можете получить пример php, но он не нужен для этого базового примера.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]