Jump to content

Edit History

Mastiff

Mastiff

Oops! Her mangler det tydeligvis noe! Jeg har ikke definert pinnene til INA-en! :rolleyes: Eller skal jeg det? Jeg skjønner ikke det ut fra eksemplene. Jeg har oppsett med SDA på 21 g SCL på 22, samme som i ESP-home. Her er hele den jeg har nå, jeg fatter ikke hvor jeg skal definere pinnene:


 

Sitat

 

#include <WebServer.h>
#include "Wire.h"
#include "Adafruit_INA219.h"

/* Put your SSID & Password */
const char* ssid = "Starthjelp";  // Enter SSID here
const char* password = "";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,4,1);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);
Adafruit_INA219 ina219;
uint8_t LED1pin = 16;
bool LED1status = LOW;

uint8_t LED2pin = 17;
bool LED2status = LOW;

float busvoltage = 0;

unsigned long timer;

 void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  digitalWrite(LED1pin, HIGH);
  digitalWrite(LED2pin, HIGH);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);
 
  server.begin();
  Serial.println("HTTP server started");
  long timer = 0;
  ina219.begin();
}

void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, LOW);}
  else
  {digitalWrite(LED1pin, HIGH);}
 
  if(LED2status)
  {digitalWrite(LED2pin, LOW);}
  else
  {digitalWrite(LED2pin, HIGH);}


if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status, busvoltage));
  if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status, busvoltage));
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status, busvoltage));
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true, busvoltage));
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false, busvoltage));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat, float busvoltage){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>Starthjelp</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center; charset: utf-8;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #e30022db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #e30022db;}\n";
  ptr +=".button-on:active {background-color: #34495e;}\n";
  ptr +=".button-off {background-color: #66ff00;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +=(float)busvoltage;
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>Batterispenning</h1>\n";
  ptr +=(busvoltage);
  ptr +="\n";
  ptr +="\n";
  ptr +="<h1>Starthjelp</h1>\n";
  ptr +="<h3>Sett hovedbryteren til batteri 2 eller begge, og aktiver releene</h3>\n";
 
   if(led1stat)
  {ptr +="<p>Rele 1: tilkoblet</p><a class=\"button button-off\" href=\"/led1off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 1: frakoblet</p><a class=\"button button-on\" href=\"/led1on\">Koble til</a>\n";}

  if(led2stat)
  {ptr +="<p>Rele 2: tilkoblet</p><a class=\"button button-off\" href=\"/led2off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 2: frakoblet</p><a class=\"button button-on\" href=\"/led2on\">Koble til</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

 

 

 

Edit igjen: Jeg tror ikke det skal defineres, jeg fant en tutorial,  https://diyi0t.com/ina219-tutorial-for-arduino-and-esp/ som sa at den skulle kobles på pinne 21 og 22, og den er koblet riktig ifølge den. Så da er det noe annet som ikke er som det skal være. Jeg sverger på at hvis jeg bare får denne til å funke, skal jeg aldri mer sette mine bein i Arduino IDE, annet enn for å bruke nøyaktig samme koden!  :lol:

Mastiff

Mastiff

Oops! Her mangler det tydeligvis noe! Jeg har ikke definert pinnene til INA-en! :rolleyes: Eller skal jeg det? Jeg skjønner ikke det ut fra eksemplene. Jeg har oppsett med SDA på 21 g SCL på 22, samme som i ESP-home. Her er hele den jeg har nå, jeg fatter ikke hvor jeg skal definere pinnene:


 

Sitat

 

#include <WebServer.h>
#include "Wire.h"
#include "Adafruit_INA219.h"

/* Put your SSID & Password */
const char* ssid = "Starthjelp";  // Enter SSID here
const char* password = "";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,4,1);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);
Adafruit_INA219 ina219;
uint8_t LED1pin = 16;
bool LED1status = LOW;

uint8_t LED2pin = 17;
bool LED2status = LOW;

float busvoltage = 0;

unsigned long timer;

 void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  digitalWrite(LED1pin, HIGH);
  digitalWrite(LED2pin, HIGH);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);
 
  server.begin();
  Serial.println("HTTP server started");
  long timer = 0;
  ina219.begin();
}

void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, LOW);}
  else
  {digitalWrite(LED1pin, HIGH);}
 
  if(LED2status)
  {digitalWrite(LED2pin, LOW);}
  else
  {digitalWrite(LED2pin, HIGH);}


if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status, busvoltage));
  if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status, busvoltage));
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status, busvoltage));
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true, busvoltage));
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false, busvoltage));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat, float busvoltage){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>Starthjelp</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center; charset: utf-8;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #e30022db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #e30022db;}\n";
  ptr +=".button-on:active {background-color: #34495e;}\n";
  ptr +=".button-off {background-color: #66ff00;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +=(float)busvoltage;
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>Batterispenning</h1>\n";
  ptr +=(busvoltage);
  ptr +="\n";
  ptr +="\n";
  ptr +="<h1>Starthjelp</h1>\n";
  ptr +="<h3>Sett hovedbryteren til batteri 2 eller begge, og aktiver releene</h3>\n";
 
   if(led1stat)
  {ptr +="<p>Rele 1: tilkoblet</p><a class=\"button button-off\" href=\"/led1off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 1: frakoblet</p><a class=\"button button-on\" href=\"/led1on\">Koble til</a>\n";}

  if(led2stat)
  {ptr +="<p>Rele 2: tilkoblet</p><a class=\"button button-off\" href=\"/led2off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 2: frakoblet</p><a class=\"button button-on\" href=\"/led2on\">Koble til</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

 

 

Mastiff

Mastiff

Oops! Her mangler det tydeligvis noe! Jeg har ikke definert pinnene til INA-en! :rolleyes: Her er hele den jeg har nå, jeg skal prøve å finne riktig sted for å sette inn pinnene:


 

Sitat

 

#include <WebServer.h>
#include "Wire.h"
#include "Adafruit_INA219.h"

/* Put your SSID & Password */
const char* ssid = "Starthjelp";  // Enter SSID here
const char* password = "";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,4,1);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);
Adafruit_INA219 ina219;
uint8_t LED1pin = 16;
bool LED1status = LOW;

uint8_t LED2pin = 17;
bool LED2status = LOW;

float busvoltage = 0;

unsigned long timer;

 void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  digitalWrite(LED1pin, HIGH);
  digitalWrite(LED2pin, HIGH);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);
 
  server.begin();
  Serial.println("HTTP server started");
  long timer = 0;
  ina219.begin();
}

void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, LOW);}
  else
  {digitalWrite(LED1pin, HIGH);}
 
  if(LED2status)
  {digitalWrite(LED2pin, LOW);}
  else
  {digitalWrite(LED2pin, HIGH);}


if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status, busvoltage));
  if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status, busvoltage));
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status, busvoltage));
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true, busvoltage));
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false, busvoltage));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat, float busvoltage){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>Starthjelp</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center; charset: utf-8;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #e30022db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #e30022db;}\n";
  ptr +=".button-on:active {background-color: #34495e;}\n";
  ptr +=".button-off {background-color: #66ff00;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +=(float)busvoltage;
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>Batterispenning</h1>\n";
  ptr +=(busvoltage);
  ptr +="\n";
  ptr +="\n";
  ptr +="<h1>Starthjelp</h1>\n";
  ptr +="<h3>Sett hovedbryteren til batteri 2 eller begge, og aktiver releene</h3>\n";
 
   if(led1stat)
  {ptr +="<p>Rele 1: tilkoblet</p><a class=\"button button-off\" href=\"/led1off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 1: frakoblet</p><a class=\"button button-on\" href=\"/led1on\">Koble til</a>\n";}

  if(led2stat)
  {ptr +="<p>Rele 2: tilkoblet</p><a class=\"button button-off\" href=\"/led2off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 2: frakoblet</p><a class=\"button button-on\" href=\"/led2on\">Koble til</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

 

 

Mastiff

Mastiff

Her er hele den jeg har nå:


 

Sitat

 

#include <WebServer.h>
#include "Wire.h"
#include "Adafruit_INA219.h"

/* Put your SSID & Password */
const char* ssid = "Starthjelp";  // Enter SSID here
const char* password = "";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,4,1);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);
Adafruit_INA219 ina219;
uint8_t LED1pin = 16;
bool LED1status = LOW;

uint8_t LED2pin = 17;
bool LED2status = LOW;

float busvoltage = 0;

unsigned long timer;

 void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  digitalWrite(LED1pin, HIGH);
  digitalWrite(LED2pin, HIGH);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);
 
  server.begin();
  Serial.println("HTTP server started");
  long timer = 0;
  ina219.begin();
}

void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, LOW);}
  else
  {digitalWrite(LED1pin, HIGH);}
 
  if(LED2status)
  {digitalWrite(LED2pin, LOW);}
  else
  {digitalWrite(LED2pin, HIGH);}


if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status, busvoltage));
  if ((timer + 20000) > millis()) {
  busvoltage = ina219.getBusVoltage_V();

  timer = millis();

  }
 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status, busvoltage));
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status, busvoltage));
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true, busvoltage));
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false, busvoltage));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat, float busvoltage){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>Starthjelp</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center; charset: utf-8;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #e30022db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #e30022db;}\n";
  ptr +=".button-on:active {background-color: #34495e;}\n";
  ptr +=".button-off {background-color: #66ff00;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +=(float)busvoltage;
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>Batterispenning</h1>\n";
  ptr +=(busvoltage);
  ptr +="\n";
  ptr +="\n";
  ptr +="<h1>Starthjelp</h1>\n";
  ptr +="<h3>Sett hovedbryteren til batteri 2 eller begge, og aktiver releene</h3>\n";
 
   if(led1stat)
  {ptr +="<p>Rele 1: tilkoblet</p><a class=\"button button-off\" href=\"/led1off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 1: frakoblet</p><a class=\"button button-on\" href=\"/led1on\">Koble til</a>\n";}

  if(led2stat)
  {ptr +="<p>Rele 2: tilkoblet</p><a class=\"button button-off\" href=\"/led2off\">Koble fra</a>\n";}
  else
  {ptr +="<p>Rele 2: frakoblet</p><a class=\"button button-on\" href=\"/led2on\">Koble til</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

 

 



×
×
  • Create New...