Hi All,
I’m not a totally beginner, but… near that It is my first post here cause I got stuck with my firmware…
I tried to modify my firmware to hand over values to a PHP page for processing them later… I used the HttpClient library and combined it with my code… but after that firmware is not flashable… It always ends up with an SOS…
Maybe someone can give me a hint what I have done wrong?
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"
/*
Pulse counter to measure used kWh and calculate current W usage from a GM3D
GND ---\
|
O 10k
|
D3 ----+------ 41
3v3 -----------42
*/
//für den HTTP Client
unsigned int nextTime = 0; // Next time to contact the server
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
//Versuch Nr
byte TryNr = 105;
// Eltako pulse lenght 30ms
byte minPulseWidth = 25;
unsigned long PulseTime=0;
volatile unsigned int PulseCount=0; //Zählt die Impule die länger als 25ms sind
volatile unsigned int DifPulseCount=0; //Anzahl der Impule zwischen zwei Meldungen
volatile unsigned int OldPulseCount=0; //Zur Berechnung benötigt
volatile unsigned long PulsePower=0;
volatile unsigned int kwhCount=0;
int Timestamp=0;
String deviceID=0;
void blink() {
if ( (millis() - PulseTime) > minPulseWidth) {
PulseCount++;
kwhCount = PulseCount / 2000;
}
}
void setup() {
pinMode(D3, INPUT);
attachInterrupt(D3, blink, RISING);
Particle.publish("power-meter-reporter", "started -"+String(TryNr));
}
void loop() {
Timestamp = Time.now();
deviceID = Particle.deviceID();
DifPulseCount = PulseCount - OldPulseCount; //Berechnet die Fiffernz zur letzten Meldung
PulsePower = DifPulseCount * 30; // DifPulseCount / 2000 * 1000 / 1 * 60; // Könnte die Watt im Zeitraum 1 Minute (delay unten) berechnen
String data = "Pulses:" + String(PulseCount) + ", Dif:" + String(DifPulseCount) + ", Kwh:" + String(kwhCount) + ", Power:" + String(PulsePower);
OldPulseCount = PulseCount; // Setzt den akutellen Wert
//http Client
request.hostname = "diefrieds.de";
request.port = 80;
request.path = "/diefrieds/Testumgebung/Photon/";
request.body = "deviceID=" + deviceID + "&Timestamp=" + Timestamp + "&PulseCount=" + PulseCount + "&DifPulseCount=" + DifPulseCount + "&kwhCount=" + kwhCount + "&PulsePower=" + PulsePower;
http.get(request, response, headers);
delay(60000); //Publish every (10Sec = 10000, 60sec = 60000)
}
Thanks in advance!!