Skip to content

Commit

Permalink
Version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
peterarandis committed Nov 18, 2019
1 parent 4a0a1ff commit 14e047f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 203 deletions.
39 changes: 13 additions & 26 deletions H60-OS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <ESP8266HTTPClient.h> // Web Client
#include <SoftwareSerial.h> // Serial port for H1
#include <ArduinoJson.h> // Json parser support
#include <FS.h> // SPIFFS SPI-Flash Filsystem, Used for Webserver
#include "HD_Globals.h"
SoftwareSerial H1(13, 12, false, 1024); // Init software serial Pin 13, 12, non inv, buff for H1 H60
os_timer_t myTimer; // Init soft interrupt timer
Expand All @@ -31,7 +30,6 @@ void setup() { // H60 Boot sequence

pinMode(LED, OUTPUT); // Initialize the LED_BUILTIN pin as an output
digitalWrite(LED, LOW); // LED Status: ON: Init | Quick-blink: WifiOK, No Online | One-sec-blink: All OK
SPIFFS.begin(); // Initialize filesystem för Config, FW och Web buffering
Serial.begin(115200); // Debug serial usb setup
H1.begin(19200); // H1 soft serial setup

Expand Down Expand Up @@ -96,13 +94,13 @@ void timerCallback(void *pArg) { // Every second
if (digitalRead(D2) == LOW) { // Read button press
B1_Count++; // Button 1
B1_Pushed=true;
Serial.println("Button Pushed " + String(B1_Count) + " sec");
Serial.println("Button Pushed " + String(B1_Count) + " sec");

}
else
{ // Button release
//if (B1_Pushed && B1_Count == 1) { flash_ip=true; } // telegrafera ip sista tecken om touchar knapp
//if (B1_Count >5 ) { config("CFG WIFI_SSID=");config("CFG DHCP_ENAB=0");config("CFG WEB_ENABLED=1");config("CFG HD_ONLINE=1"); } // Default inst

//if (B1_Count >5 ) {} // Button 5 sek
B1_Count=0;
B1_Pushed = false;
}
Expand All @@ -123,36 +121,25 @@ void loop() {
FlashLed();

// ======= Every SEK ========

if (onesec){

onesec=0;
if (onesec){ onesec=false; }


}



// ======= VARJE MINUT ========
if (onemin){ // Kör varje ny minut utanför timer rutin då den krashar annars.
// ======= EVERY MINUTE ========
if (onemin){

if (WiFi.status() == 3) state_Wifi=true; else state_Wifi=false; // Check Wifi status 3 = ok, 0/1/6=fault

uptime++;
mincount=0;
onemin=false;
if (WiFi.status() == 3) state_Wifi=true; else state_Wifi=false; // Check Wifi status 3 = ok, 0/1/6=fault
uptime++;
mincount=0;
onemin=false;
}

// ======= VAR 5e SEKUND ========
if (every5seconds) { // Kör var 10:e sekund
//Serial.print("+");
// ======= EVERY 5th SECOND ========
if (every5seconds) {
every5seconds=0;
secondsCount=0;
H1_CommInit(0);



}
}

}

Expand Down
5 changes: 1 addition & 4 deletions HD_Globals.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Prototyper -------------
// Prototypes -------------
String H1_format_value (char idx, char type);
String H1_unit_value (char idx);
byte H1_IDXtoID (String idx);
Expand Down Expand Up @@ -31,7 +31,6 @@ char g_wifi_rssi[20] = "";
char g_wifi_ip[20];
char g_wifi_mac[20];

String restart_reason = "unknown";

// H1 comm related
String H1_Ver="";
Expand All @@ -52,5 +51,3 @@ bool state_H1Comm=0;
bool state_HPComm=0;
bool state_XL_ListRead = false;
bool state_Indexes_Received=0;
//bool state_Startuplog_Sent=0; // Vid uppstart skickas en log efter 1 min, detta görs bara en gång
//bool state_SupportServer = false;
30 changes: 5 additions & 25 deletions HD_H1comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ void H1_HandleData() { // Handle incoming H1 data

}

// DETECT AND CORRECT MISSING FIRMWARE
else if (incomingH1.substring(0,10)=="Bootloader") {//and g_startseq == START_INIT:
trace("H1 Booted","LOG LF SER");
// H1_Booted = true;

}


else {

Expand All @@ -106,7 +99,6 @@ void H1_HandleData() { // Handle incoming H1 data
String H1_PrintVpModel()
{
String vpmod;
//String t;

if (H1_Type == "00") vpmod = "Rego 600";
else if (H1_Type == "05") vpmod = "Rego 400";
Expand All @@ -119,33 +111,25 @@ String vpmod;
else if (H1_Type == "70") vpmod = "Thermia Villa";
else return "Not initialized";

//t = vpmod + ", Firmware: " + H1_Type+H1_Ver; //trace (t,"SER LOG LF");
return vpmod + ", Firmware: " + H1_Type+H1_Ver; //trace (t,"SER LOG LF");

//return t;

}
//-------------------------------------------------------------------------------------------------
void H1_Recv() { // Data mottages från H1 Interface
void H1_Recv() { // Data from H1 controller


static byte ndx = 0;
char endMarker = '\r';
char rc;

#ifdef simulator
return;
#endif

while (H1.available() > 0 && new_H1_data == false) {
rc = H1.read();

//if (H1_FlashMode) { if (receivedCharsH1.endsWith("Bootloader..")) {H1_Booted = true; Serial.print ("+");} }
// if (H1_FlashMode) { if (receivedCharsH1.indexOf("Bootloader..")) {Serial.print (receivedCharsH1);receivedCharsH1="";H1_Booted = true;} }



if (rc != endMarker) {

receivedCharsH1 += rc;

ndx++;
Expand All @@ -168,16 +152,15 @@ void H1_Recv() { // Data mottages från H1 Interface
receivedCharsH1="";
}




yield();
}
//}
}

//--------------------------------------------------------------------------------------------------------

void H1_hp_set(String idx, int value)
void H1_hp_set(String idx, int value) // Set parameter in Heat pump
{
char v_hex[10];
String s;
Expand All @@ -194,7 +177,6 @@ void H1_hp_set(String idx, int value)
}
//-------------------------------------------------------------------------------------------------


String H1_unit_value (char idx)

{
Expand Down Expand Up @@ -229,9 +211,7 @@ String H1_format_value (char idx, char type)
{
char z[2];
char *endptr;
//String valprint;
String val;

float v;
int i;
int unit;
Expand Down
102 changes: 5 additions & 97 deletions HD_Utilities.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

void trace (String text, String func) ;



// Time / NTP
#define TZ 0 // (utc+) TZ in hours
#define DST_MN 60 // use 60mn for summer time in some countries
Expand All @@ -12,10 +10,6 @@ void trace (String text, String func) ;
timeval tv;
time_t now;





void FlashLed()
{

Expand All @@ -26,10 +20,10 @@ void FlashLed()
const int pattern[][15]= { {1,5,5000,0}, // 0: Dark
{1,70,3000,0}, // 1: . Wifi Err
{1,70,300,70,3000,0}, // 2: . . H1 Err
{1,70,300,70,300,70,3000,0}, // 3: . . . HD Online Err
{1,70,300,70,70,300,300,70,3000,0}, // 4: . . . . Ledig för ytterligare err
{1,70,300,70,300,70,3000,0}, // 3: . . . Not used
{1,70,300,70,70,300,300,70,3000,0}, // 4: . . . . Not used
{1,1000,1000,0}, // 5: - - Slow flash, all OK
{1,50,50,0}, // 6: ....... Super fast flash, AP mode
{1,50,50,0}, // 6: ....... Super fast flash, AP mode not used
{1,70,300,70,300,700,2000,0}, // 7: . . - Test not used
};

Expand All @@ -43,7 +37,7 @@ if(!flash_ip)
}


if (!pattern[pattern_no][pattern_pos]) pattern_pos=0; // Nollställ och starta om
if (!pattern[pattern_no][pattern_pos]) pattern_pos=0;
if (pattern_pos == 0) {m = millis(); digitalWrite(LED, HIGH);pattern_pos++;} // INIT
else if ( pattern_pos % 2 == 0)
{if (millis() > m + pattern[pattern_no][pattern_pos]) {m = millis();digitalWrite(LED, HIGH);pattern_pos++;} } // EVEN 2,4,6
Expand All @@ -56,9 +50,6 @@ if(!flash_ip)

//-----------------------------------------------------------------------------------------------




void rssi_update()
{
int i = WiFi.RSSI();
Expand All @@ -70,108 +61,25 @@ void rssi_update()
sprintf(g_wifi_rssi,"%s %ddBm", s, i); // Uppdatera signalstyrka
}

//-----------------------------------------------------------------------------------------------
void DispOled(char *text) {
/*
oled.clear();
//oled.drawString(0, 0, text);
//oled.drawString(0, 0, receivedChars);
oled.drawString(0, 15, g_wifi_ip);
oled.drawString(0, 30, g_wifi_rssi);
oled.drawString(0, 45, g_wifi_mac);
oled.display();
*/
}
//-----------------------------------------------------------------------------------------------

void trace (String text, String func) // SER LOG LF
{
Serial.println(text);
}

//-----------------------------------------------------------------------------------------------


//===============================================================================
// behöver inte returnera nått, modifierar originalvariabeln
char *tolow (char *s)
{
char *p;
for (p = s; *p != '\0'; ++p) { *p = tolower(*p); }
return s;
}

//===============================================================================


//------------------------------------------------------------------------------------------------------------------
String get_restart_reason ()
{
File f = SPIFFS.open("/restart_reason.txt", "r");
if (f) {
if (f.available()) return(" " + f.readStringUntil(','));
}
return " ";
}


void restart_h60 (bool restart)
{

File f = SPIFFS.open("/restart_reason.txt", "w");
if (f) {f.println(restart_reason); f.close(); }

if (restart) ESP.restart();

}

//---------------------------------------------------------------------------------------------------------------

String chkmem()
{
// Check memory avalible, Critical under 9000 bytes
long fh = ESP.getFreeHeap();
char fhc[20];
ltoa(fh, fhc, 10);
return String(fhc);
}


//------------------------------------------------------------------------------------------------------------------



String urlencode(String str) // URL encode string for web posting
{
String encodedString="";
char c;
char code0;
char code1;
char code2;
for (int i =0; i < str.length(); i++){
c=str.charAt(i);
if (c == ' '){
encodedString+= '+';
} else if (isalnum(c)){
encodedString+=c;
} else{
code1=(c & 0xf)+'0';
if ((c & 0xf) >9){
code1=(c & 0xf) - 10 + 'A';
}
c=(c>>4)&0xf;
code0=c+'0';
if (c > 9){
code0=c - 10 + 'A';
}
code2='\0';
encodedString+='%';
encodedString+=code0;
encodedString+=code1;
//encodedString+=code2;
}
yield();
}
return encodedString;
}


Loading

0 comments on commit 14e047f

Please sign in to comment.