grillmeister27
Militanter Veganer
Die Klinkenbuchsen für die Maverick Messfühler sind Mono, 2.5 mm
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
#define DST_IP "184.106.153.149" // IP der Internetseite Thinkspeak.com
//Vertbindung zum web server
String cmd = "AT+CIPSTART="AT+CIPSTART=\"TCP\",\"184.106.153.149\",80\""; //(sollte passen) ? make this command: AT+CPISTART="TCP","199.199.199.199",80 ?????
cmd += DST_IP;
cmd += "\",80";
Serial.println(cmd);
//warten auf Verlinkung
delay(300);
//HTTP GET Request
cmd = "GET /datei.php?Wert1="; // Datei des Internetservices aufrufen
cmd += Temperatur;
cmd += "&Wert2=";
cmd += Temperatur1;
cmd +="&VCC=";
cmd += vcc;
cmd += " HTTP/1.0\r\n";
cmd += "Host: 217.160.107.197\r\n\r\n"; // ?????
/* http://thingspeak.com client for Arduino and ESP8266
programmed by 'jurs' for Henry der Rote
For ESP8266 ESP-01 firmware: [Vendor:www.ai-thinker.com Version:0.9.2.4]
Alpha pre-release; Not fully working yet!!!
*/
#define BAUD 9600L /// ESP8266 default baudrate
#define WLAN_SSID "xxxxx" // your WLANs SSID
#define WLAN_PASS "xxxxx" // your WLANs password
#define APIKEY "xxxxx" // your Thingspeak.com API-Key
#define APISERVER "api.thingspeak.com"
#define UPDATEINTERVAL 30000L // Update each 30 seconds
#define espSerial Serial1 // define which serial port to use with ESP8266 module
int readTempSensor()
{ // replace with temperature reading, return integer value
return 100+random(50);
}
char* readResponse(long timeout)
{
static char str[21];
int count=0;
str[0]=0;
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available())
{
char c=espSerial.read();
Serial.write(c);
if (c>=32 && count<sizeof(str)-1)
{
str[count]=c;
count++;
str[count]=0;
}
if (c=='\n' && count==0)
{
}
else if (c=='\n')
{
return str;
}
}
}
return NULL;
}
char* readATresponse(char* command, long timeout)
{
static char str[81];
int count=0;
str[0]=0;
espSerial.print(command);
espSerial.println();
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available())
{
char c=espSerial.read();
Serial.write(c);
if (c>=32 && count<sizeof(str)-1)
{
str[count]=c;
count++;
str[count]=0;
}
if (c=='\n' && count==0)
{
}
else if (c=='\n')
{
// Serial.print("Got: ");Serial.println(str);
if (strcmp(command,str)==0)
{
// Serial.println("(is Echo)");
count=0;
str[0]=0;
}
else return str;
}
}
}
Serial.println("\n\rTIMEOUT");
return NULL;
}
void waitShowResponse(long timeout)
{
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available()) Serial.write(espSerial.read());
}
}
boolean thingSpeakUpdate()
{
char buf[81];
// prepare TCP connection
snprintf(buf,sizeof(buf),"AT+CIPSTART=\"TCP\",\"%s\",80", APISERVER);
char* str=readATresponse(buf, 5000);
if (str!=NULL)
{
Serial.print("Response: "); Serial.println(str);
}
// waitShowResponse(2000); // wait for "Linked" message
str=readResponse(3000);
Serial.print("Link Connect State: ");
if (str!=NULL) Serial.println(str); else Serial.println("NULL");
// prepare GET string
int temperature=readTempSensor();
snprintf(buf,sizeof(buf),"GET /update?api_key=%s&field1=%d HTTP/1.0\r\n\r\n",APIKEY,temperature);
char buf2[21];
// prepare sending buffer length
snprintf(buf2,sizeof(buf2),"AT+CIPSEND=%d",strlen(buf));
str=readATresponse(buf2, 2000);
// if (strcmp(str,">")==0)
Serial.print(millis()/1000.0);Serial.println("+++");
waitShowResponse(100);
espSerial.print(buf);
return true;
}
void initWifi()
{
espSerial.println("AT+RST");
waitShowResponse(4000);
readATresponse("AT+CWQAP",1000); // quit from WIFI access point
readATresponse("AT+CWMODE=1",1000);
char buf[41];
// connect to WIFI access point
snprintf(buf,sizeof(buf),"AT+CWJAP=\"%s\",\"%s\"", WLAN_SSID, WLAN_PASS);
readATresponse(buf,15000); // try connecting to WLAN router for 15 seconds
readATresponse("AT+CIPMUX=0",1);
}
void setup()
{
Serial.begin(BAUD);
espSerial.begin(BAUD);
Serial.println();
Serial.println("ESP8266 Demo Test by 'jurs'");
waitShowResponse(6000);
for (int i=0;i<5;i++)
{
char* str=readATresponse("AT", 1000);
if (strcmp(str,"OK")==0) break;
waitShowResponse(2000);
}
}
unsigned long lastUpdate;
void loop()
{
if(espSerial.available()) Serial.write(espSerial.read());
if(Serial.available())
{
char c=Serial.read();
if (c=='#')
{
delay(10);
while (Serial.available()) Serial.read();
initWifi();
}
else
espSerial.write(c);
}
if (millis()-lastUpdate>=UPDATEINTERVAL)
{
lastUpdate+=UPDATEINTERVAL;
thingSpeakUpdate();
}
}
/* http://thingspeak.com client for Arduino and ESP8266
programmed by 'jurs' for Henry der Rote
For ESP8266 ESP-01 firmware: [Vendor:www.ai-thinker.com Version:0.9.2.4]
Alpha pre-release; Not fully working yet!!!
*/
#define BAUD 9600L /// ESP8266 default baudrate
#define WLAN_SSID "xxxxx" // your WLANs SSID
#define WLAN_PASS "xxxxx" // your WLANs password
#define APIKEY "xxxxx" // your Thingspeak.com API-Key
#define APISERVER "api.thingspeak.com"
#define UPDATEINTERVAL 30000L // Update each 30 seconds
#define espSerial Serial1 // define which serial port to use with ESP8266 module
String stringValue = "";
const int numProbes = 2;
const int bufferLength = 30;
int Temperatur;
int Temperatur1;
float temp;
// probe datastructure
struct Probe {
String name;
int pin;
double A;
double B;
double C;
int buffer[bufferLength];
int currentTemp;
int resistor;
};
// probes array
Probe probes[2];
int readTempSensor()
{ // replace with temperature reading, return integer value
Temperatur; // oder für Geber 2: Temperatur1
}
char* readResponse(long timeout)
{
static char str[21];
int count=0;
str[0]=0;
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available())
{
char c=espSerial.read();
Serial.write(c);
if (c>=32 && count<sizeof(str)-1)
{
str[count]=c;
count++;
str[count]=0;
}
if (c=='\n' && count==0)
{
}
else if (c=='\n')
{
return str;
}
}
}
return NULL;
}
char* readATresponse(char* command, long timeout)
{
static char str[81];
int count=0;
str[0]=0;
espSerial.print(command);
espSerial.println();
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available())
{
char c=espSerial.read();
Serial.write(c);
if (c>=32 && count<sizeof(str)-1)
{
str[count]=c;
count++;
str[count]=0;
}
if (c=='\n' && count==0)
{
}
else if (c=='\n')
{
// Serial.print("Got: ");Serial.println(str);
if (strcmp(command,str)==0)
{
// Serial.println("(is Echo)");
count=0;
str[0]=0;
}
else return str;
}
}
}
Serial.println("\n\rTIMEOUT");
return NULL;
}
void waitShowResponse(long timeout)
{
unsigned long startTime=millis();
while (millis()-startTime<timeout)
{
if (espSerial.available()) Serial.write(espSerial.read());
}
}
boolean thingSpeakUpdate()
{
char buf[81];
// prepare TCP connection
snprintf(buf,sizeof(buf),"AT+CIPSTART=\"TCP\",\"%s\",80", APISERVER);
char* str=readATresponse(buf, 5000);
if (str!=NULL)
{
Serial.print("Response: "); Serial.println(str);
}
// waitShowResponse(2000); // wait for "Linked" message
str=readResponse(3000);
Serial.print("Link Connect State: ");
if (str!=NULL) Serial.println(str); else Serial.println("NULL");
// prepare GET string
int temperature=readTempSensor();
snprintf(buf,sizeof(buf),"GET /update?api_key=%s&field1=%d HTTP/1.0\r\n\r\n",APIKEY,temperature);
char buf2[21];
// prepare sending buffer length
snprintf(buf2,sizeof(buf2),"AT+CIPSEND=%d",strlen(buf));
str=readATresponse(buf2, 2000);
// if (strcmp(str,">")==0)
Serial.print(millis()/1000.0);Serial.println("+++");
waitShowResponse(100);
espSerial.print(buf);
return true;
}
void initWifi()
{
espSerial.println("AT+RST");
waitShowResponse(4000);
readATresponse("AT+CWQAP",1000); // quit from WIFI access point
readATresponse("AT+CWMODE=1",1000);
char buf[41];
// connect to WIFI access point
snprintf(buf,sizeof(buf),"AT+CWJAP=\"%s\",\"%s\"", WLAN_SSID, WLAN_PASS);
readATresponse(buf,15000); // try connecting to WLAN router for 15 seconds
readATresponse("AT+CIPMUX=0",1);
}
void setup()
{
// configure probes
Probe p0 = Probe();
p0.name = "ET-732-1";
p0.pin = A2;
p0.A = 5.36924e-4;
p0.B = 1.91396e-4;
p0.C = 6.60399e-8;
p0.resistor = 22000;
probes[0] = p0;
Probe p1 = Probe();
p1.name = "ET-732-2";
p1.pin = A4;
p1.A = 5.36924e-4;
p1.B = 1.91396e-4;
p1.C = 6.60399e-8;
p1.resistor = 22001;
probes[1] = p1;
delay(2000);
Serial.begin(BAUD);
espSerial.begin(BAUD);
Serial.println();
Serial.println("ESP8266 Demo Test by 'jurs'");
waitShowResponse(6000);
for (int i=0;i<5;i++)
{
char* str=readATresponse("AT", 1000);
if (strcmp(str,"OK")==0) break;
waitShowResponse(2000);
}
}
unsigned long lastUpdate;
void loop()
{
int sensorValue = 0;
int outputValue = 0;
// loop für jeden Geber
for (int i = 0; i < numProbes; i++) {
Probe *ptr = &probes[i];
// Wert einlesen:
outputValue = readAndOverSample((*ptr).pin, (*ptr).A, (*ptr).B, (*ptr).C, (*ptr).resistor);
// Wert in den Buffer schreiben
(*ptr).currentTemp = outputValue;
for (int i = bufferLength -1; i >= 1; i--) {
(*ptr).buffer[i] = (*ptr).buffer[i-1];
}
(*ptr).buffer[0] = outputValue;
}
for (int i = 0; i < numProbes; i++) {
Probe *ptr = &probes[i];
// maximal 4 Geber!
int x; int y;
if (i % 2 == 0) {
x = 0;
}
else if (i % 2 == 1) {
x = 8;
}
if (i / 2 == 0) {
y = 0;
}
else if (i / 2 == 1) {
y = 1;
}
}
delay(10000);
int per = 50000/numProbes/5000;
for (int p = 0; p < per; p++) {
for (int i = 0; i < numProbes; i++) {
Probe *ptr = &probes[i];
// Durchschnitt errechnen 5 Minuten
int five, fifteen, thirty;
int accum = 0;
for (int i = 0; i < 5; i++) {
if ((*ptr).buffer == 0) {
accum = 0;
break;
}
accum += (*ptr).buffer[i];
}
five = accum/5;
// Durchschnitt errechnen 15 Minuten
accum = 0;
for (int i = 0; i < 15; i++) {
if ((*ptr).buffer == 0) {
accum = 0;
break;
}
accum += (*ptr).buffer[i];
}
fifteen = accum/15;
// Durchschnitt errechnen 30 Minuten
accum = 0;
for (int i = 0; i < 30; i++) {
if ((*ptr).buffer == 0) {
accum = 0;
break;
}
accum += (*ptr).buffer[i];
}
thirty = accum/30;
}
}
if(espSerial.available()) Serial.write(espSerial.read());
if(Serial.available())
{
char c=Serial.read();
if (c=='#')
{
delay(10);
while (Serial.available()) Serial.read();
initWifi();
}
else
espSerial.write(c);
}
if (millis()-lastUpdate>=UPDATEINTERVAL)
{
lastUpdate+=UPDATEINTERVAL;
thingSpeakUpdate();
}
}
int readAndOverSample(int apin, double A, double B, double C, int resistor) {
int sensorvalue = 0;
unsigned int accumulated = 0;
int numsamples = 64;
int n = 0;
sensorvalue = analogRead(apin);
delay(2);
// einlesen der 64 samples
for (int i = 0; i < numsamples; i++) {
sensorvalue = analogRead(apin);
if (sensorvalue == 0 || sensorvalue >= 1023) {
return -1;
}
accumulated += sensorvalue;
n++;
delay(2);
}
unsigned int ADCmax = (1 << 13) - 1;
unsigned int ADCval = accumulated >> 3;
float R, T;
R = log( resistor / ((ADCmax/(float)ADCval) - 1.0f));
T = 1.0f / ((C * R * R + B) * R + A);
temp = (T - 273.15f);
// Serial.print("temp="); Serial.println(temp);
if (resistor > 22000) {
Temperatur = temp; // Wert für Internetseite speichern
}
else {
Temperatur1 = temp; // Wert für Internetseite speichern
}
}
ESP8266 Demo Test by 'jurs'
AT
TIMEOUT
AT
TIMEOUT
AT
TIMEOUT
AT
TIMEOUT
AT
TIMEOUT
AT+CIPSTART="TCP","api.thingspeak.com",80
TIMEOUT
Link Connect State: NULL
AT+CIPSEND=58
TIMEOUT
43.14+++
GET /update?api_key=xxxxx&field1=0 HTTP/1.0
Response: T /update?api_key=xxxxx&field1=0 HTTP/1.0
AT+CIPSTART="TCP","api.thingspeak.com",80
Link Connect State: AT+CIPSTART="TCP","a
AT+CIPSEND=58
TIMEOUT
65.67+++
GET /update?api_key=xxxxx&field1=0 HTTP/1.0
Response: /update?api_key=xxxxx&field1=0 HTTP/1.0
AT+CIPSTART="TCP","api.thingspeak.com",80
Link Connect State: AT+CIPSTART="TCP","a
AT+CIPSEND=58
TIMEOUT
98.33+++
GET /update?api_key=xxxxx&field1=0 HTTP/1.0
Response: /update?api_key=xxxxx&field1=0 HTTP/1.0
ERROAT+CIPSTART="TCP","api.thingspeak.com",80
Link Connect State: ERROAT+CIPSTART="TCP
AT+CIPSEND=58
busy p...
249.31+++
OK
Linked
GET /update?api_key=xxxxx&field1=0 HTTP/1.0
Response: /update?api_key=xxxxx&field1=0 HTTP/1.0
ERROAT+CIPSTART="TCP","api.thingspeak.com",80
Link Connect State: ERROAT+CIPSTART="TCP
ALREAY CONNECT
279.62+++
AT+CIPSEND=58
> GET /update?api_key=xxxxx&field1=0 HTTP/1.0
Response: /update?api_key=xxxxx&field1=0 HTTP/1.0
SEND AT+CIPSTART="TCP","api.thingspeak.com",80
Link Connect State: SEND AT+CIPSTART="TC
ALREAY CONNECT
309.93+++
AT+CIPSEND=58
>
Sobald ich Versuche den code auf die arduino zu implementieren tut sich nix mehr!