Brauchst Du die hohe Auflösung von 16Bit wirklich? Wenn Dir 10Bit auch genügen, dann könnte ein MCP3008 auch interessant sein - der hätte gleich die 8 Kanäle, die Du eventuell brauchst.
ESP 8266 soll Wasserkühlung überwachen
-
tutter -
1. Oktober 2021 um 20:57 -
Unerledigt
-
-
ESP 8266 soll Wasserkühlung überwachen? Schau mal ob du hier fündig wirst!
-
Hat der MCP3208 nicht auch 8 Kanäle ?
-
Achja stimmt ein MCP3008 könnte ja auch gehen! davon müsste ich noch ein paar rumliegen haben. die hatte ich mal gekauft für den Raspi. Ich schau mich mal um ob es infos gibt wie man den MCP mit den ESP zusammenbringt.
Danke für den Tipp
-
So nun ist es das Ziel die Daten in eine Datenbank zu schreiben.
Auf meinen Raspberry Pi läuft Postgresql.
Es gibt auch eine Bibliothek die ich extra dafür eingebunden habe.
Der Connect und das abrufen über den Serial Monitor funktioniert wenn ich einen SQL Befehl im Monitor absende.
Jedoch gelingt es mir nicht einen Select bzw. das Resulset mir im Serial Monitor anzeigen zu lassen.
Im Block nachfolgenden Block erhalte ich stets "Unknown error". Muss ich die Klammern noch demaskieren (wenn ja wie) oder was mache ich falsch?
Code
Alles anzeigen[code] conn.execute("SELECT Version()"); msg = conn.getMessage(); if (msg) Serial.println(msg); else Serial.println("UNKNOWN ERROR"); if (conn.status() == CONNECTION_BAD) { Serial.println("Connection is bad"); pg_status = -1; [/code]
C
Alles anzeigen[code] /* * SimplePgSQL.c - Lightweight PostgreSQL connector for Arduino * Copyright (C) Bohdan R. Rau 2016 <ethanak@polip.com> * * SimplePgSQL is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * SimplePgSQL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with SimplePgSQL. If not, write to: * The Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA. */ /* * Demo program for SimplePgSQL library * Simple PostgreSQL console * Accepts: * - PostgreSQL simple queries * - \d - displays table list * - \d tablename - list table columns * - exit - closes connection */ #ifdef ESP8266 #include <ESP8266WiFi.h> #else // Uncomment line below if you use WiFi shield instead of Ethernet // #define USE_ARDUINO WIFI 1 #ifdef USE_ARDUINO_WIFI #include <WIFI.h> #else #include <Ethernet.h> #endif #endif #include <SimplePgSQL.h> IPAddress PGIP(192,168,178,29); // your PostgreSQL server IP const char ssid[] = "IOT"; // your network SSID (name) const char pass[] = "geheim"; // your network password const char user[] = "postgres"; // your database user const char password[] = "postgres"; // your database password const char dbname[] = "pi_DB"; // your database name #if defined(ESP8266) || defined(USE_ARDUINO_WIFI) int WiFiStatus; WiFiClient client; #else #define USE_ARDUINO_ETHERNET 1 EthernetClient client; byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // your mac address byte ip[] = {192, 168, 1, 177}; // your IP address #endif char buffer[1024]; PGconnection conn(&client, 0, 1024, buffer); void setup(void) { Serial.begin( #ifdef ESP8266 115200 #else 9600 #endif ); #ifdef USE_ARDUINO_ETHERNET Ethernet.begin(mac, ip); #else WiFi.begin((char *)ssid, pass); #endif } #ifndef USE_ARDUINO_ETHERNET void checkConnection() { int status = WiFi.status(); if (status != WL_CONNECTED) { if (WiFiStatus == WL_CONNECTED) { Serial.println("Connection lost"); WiFiStatus = status; } } else { if (WiFiStatus != WL_CONNECTED) { Serial.println("Connected"); WiFiStatus = status; } } } #endif static PROGMEM const char query_rel[] = "\ SELECT a.attname \"Column\",\ pg_catalog.format_type(a.atttypid, a.atttypmod) \"Type\",\ case when a.attnotnull then 'not null ' else 'null' end as \"null\",\ (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)\ FROM pg_catalog.pg_attrdef d\ WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) \"Extras\"\ FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c\ WHERE a.attrelid = c.oid AND c.relkind = 'r' AND\ c.relname = %s AND\ pg_catalog.pg_table_is_visible(c.oid)\ AND a.attnum > 0 AND NOT a.attisdropped\ ORDER BY a.attnum"; static PROGMEM const char query_tables[] = "\ SELECT n.nspname as \"Schema\",\ c.relname as \"Name\",\ CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as \"Type\",\ pg_catalog.pg_get_userbyid(c.relowner) as \"Owner\"\ FROM pg_catalog.pg_class c\ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\ WHERE c.relkind IN ('r','v','m','S','f','')\ AND n.nspname <> 'pg_catalog'\ AND n.nspname <> 'information_schema'\ AND n.nspname !~ '^pg_toast'\ AND pg_catalog.pg_table_is_visible(c.oid)\ ORDER BY 1,2"; int pg_status = 0; void doPg(void) { char *msg; int rc; if (!pg_status) { conn.setDbLogin(PGIP, user, password, dbname, "utf8"); pg_status = 1; return; } if (pg_status == 1) { rc = conn.status(); if (rc == CONNECTION_BAD || rc == CONNECTION_NEEDED) { char *c=conn.getMessage(); if (c) Serial.println(c); pg_status = -1; } else if (rc == CONNECTION_OK) { pg_status = 2; Serial.println("Enter query"); conn.execute("SELECT Version()"); msg = conn.getMessage(); if (msg) Serial.println(msg); else Serial.println("UNKNOWN ERROR"); if (conn.status() == CONNECTION_BAD) { Serial.println("Connection is bad"); pg_status = -1; } } } } void loop() { #ifndef USE_ARDUINO_ETHERNET checkConnection(); if (WiFiStatus == WL_CONNECTED) { #endif doPg(); #ifndef USE_ARDUINO_ETHERNET } #endif delay(50); } [/code]
-
Jetzt mitmachen!
Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!