Hallo,
Photon Boards von Particle sind das was ich seit Jahren gesucht habe. Eine schnell Arduino Implementierung, WLAN, „Over The Air Programming“ Preis mit ca. € 19,- auch für keine Anwendungen verträglich. Zusätzlich verwende ich in diesem Beispiel einen BME280 Sensor Angeschlossen über I²C.
Nach nur kurzer Zeit ließen sich die Daten ganz einfach per JSON RPC an IP-Symcon senden.
Hier mein Beispiel zum Nachbauen wer Lust hat…
LG, Herbert
#include „HttpClient/HttpClient.h“
This includes the library for the BME280 humidity, temperature & pressure sensor
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
This file was modified by Markus Haack (mhaack (Markus Haack) · GitHub)
in order to work with Particle Photon & Core.
***************************************************************************/
//Sensor
#include „Adafruit_BME280/Adafruit_Sensor.h“
#include „Adafruit_BME280/Adafruit_BME280.h“
#include „application.h“
#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5
#define SEALEVELPRESSURE_HPA (1015.00)
#define TOKEN „Basic aGXyYmXydEX2aXY6dSh1bS5hdDpQYXVsLTIwMTAh“ //Base 64 Encoded Username:Password
//Variablen
HttpClient http;
Adafruit_BME280 bme; // I2C
http_header_t headers = {
{ „Content-Type“, „application/json“ },
// { „Accept“ , „application/json“ },
{ „Accept“ , „/“},
{ „Authorization“ , TOKEN },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
if (!bme.begin()) {
Serial.println(„Could not find a valid BME280 sensor, check wiring!“);
while (1);
}
}
void loop() {
request.ip = {192,168,5,61};
request.port = 82;
request.path = „/api/“;
Serial.println("Sensing an upload started...");
//Temperature
request.body = payload("52389", bme.readTemperature()); //52389 = IP-Symcon ObjektID
http.post(request, response, headers);
//Pressure
request.body = payload("46947", bme.readPressure() / 100.0F);
http.post(request, response, headers);
//Humidity
request.body = payload("34298", bme.readHumidity());
http.post(request, response, headers);
//End one round
//Serial.println(response.status);
Serial.print("Application> Response status: ");
Serial.print("Data sent!");
delay(2000);
}
String payload(String id, float val) {
String returnval;
returnval = „{„id“: „0“, „jsonrpc“: „2.0“, „params“: [“;
returnval += id;
returnval += ", ";
returnval += String(val,2);
returnval += „], „method“: „SetValueFloat“}“;
return returnval;
}