Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab670a9

Browse files
committedAug 11, 2023
nothing major
1 parent 4c45572 commit ab670a9

File tree

6 files changed

+235
-172
lines changed

6 files changed

+235
-172
lines changed
 

‎buzzer.h

Lines changed: 137 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -4,142 +4,142 @@
44
int BUZZ_VOLUME = 100;
55
int buzzer_pin = -1;
66

7-
#ifdef ESP8266
8-
9-
#include <ESP8266_Tones.h> // https://github.com/Mottramlabs/ESP8266-Tone-Generator
10-
#include <Tone_Pitches.h>
11-
ESP8266_Tones BUZZER_TONE(BUZ_PIN);
12-
char szBuf[128]; // serial buffer seems to be only 128 bytes on ESP, only 64 on ATmega
13-
14-
#include <MmlMusicPWM.h> // requires #include <MmlBUZZER_MUSIC.h>
15-
// define the pin used and initialize a MusicEngine object
16-
MmlMusicPWM BUZZER_MUSIC(BUZ_PIN);
17-
18-
bool init_buzzer(){
19-
pinMode(BUZ_PIN,OUTPUT);
20-
}
21-
22-
void soundSiren(int nTimes=10)
23-
{
24-
for(int nLoop=0; nLoop<nTimes; nLoop++)
25-
{
26-
for(int nFreq=100; nFreq<2000; nFreq+=10)
27-
{
28-
BUZZER_MUSIC.tone(nFreq);
29-
delay(1);
30-
}
31-
for(int nFreq=2000; nFreq>100; nFreq-=10)
32-
{
33-
BUZZER_MUSIC.tone(nFreq);
34-
delay(1);
35-
}
36-
}
37-
}
38-
39-
void soundNoise(int nLength=30)
40-
{
41-
srand(analogRead(A0));
42-
for(int nLoop=0; nLoop<nLength; nLoop++)
43-
{
44-
for(int nTimes=1; nTimes<max(400-nLoop*5,0); nTimes++)
45-
{
46-
BUZZER_MUSIC.tone(random(100, 2000));
47-
delay(1);
48-
}
49-
BUZZER_MUSIC.noTone();
50-
delay(max(200-nLoop*5,0));
51-
}
52-
}
53-
54-
void soundNoise2(int nLength=20)
55-
{
56-
srand(analogRead(A0));
57-
for(int nLoop=0; nLoop<nLength; nLoop++)
58-
{
59-
for(int nTimes=1; nTimes<100; nTimes++)
60-
{
61-
BUZZER_MUSIC.tone(random(100, 2000));
62-
delay(1);
63-
}
64-
delay(100);
65-
}
66-
BUZZER_MUSIC.noTone();
67-
}
68-
69-
void soundNoise3(int nLength=5)
70-
{
71-
srand(analogRead(A0));
72-
for(int nLoop=0; nLoop<nLength; nLoop++)
73-
{
74-
for(int nTimes=1; nTimes<200; nTimes++)
75-
{
76-
BUZZER_MUSIC.tone(random(100, 2000));
77-
delay(10);
78-
}
79-
delay(20);
80-
}
81-
BUZZER_MUSIC.noTone();
82-
}
83-
84-
void testsounds() {
85-
// put your setup code here, to run once:
86-
BUZZER_MUSIC.play("T240 L16 O8 r1 CDEDC"); // give a short blurp
87-
// soundSiren(5);
88-
BUZZER_MUSIC.play("T240 L32 O8 r1 GDECBADGECDEDCr2GDECBADGECDEDCr1GDECBADGECDEDC"); // play a different noise
89-
// soundNoise();
90-
// delay(500);
91-
// soundNoise2();
92-
// delay(500);
93-
// soundNoise3();
94-
BUZZER_MUSIC.play("T240 L2 O2 r1 CDCECBrCDCDCD O1 r CDCDCDrCDCECB O0 r CDCDCDrCDCECB"); // play a different noise
95-
}
96-
97-
void blurp() {
98-
BUZZER_MUSIC.play("V10 T240 L16 O8 CDEDC"); // give a short blurp
99-
}
100-
101-
void blurp2() {
102-
BUZZER_MUSIC.play("T240 L16 O8 r1 CDEDC"); // give a short blurp
103-
}
104-
105-
void blurp3(){
106-
BUZZER_MUSIC.play_P(PSTR("T240 O4 L64 AB>C, T240 O4 L32 CBA V0 A \0\0")); // give a short beep
107-
}
108-
109-
void blurp4(){
110-
BUZZER_MUSIC.play("T240 O8 E64"); // give a short beep
111-
}
112-
113-
void blurp5(){
114-
BUZZER_MUSIC.play("V20 T240 O8 G64\0\0"); // give a short beep
115-
// BUZZER_MUSIC.play("T240 O8 G64\0\0"); // give a short beep
116-
}
117-
118-
void blurp6(){
119-
BUZZER_MUSIC.play("V5 T250 L64 O7 B");
120-
}
121-
122-
void playBlurpA(){
123-
blurp5();
124-
delay(50);
125-
blurp5();
126-
delay(50);
127-
blurp5();
128-
delay(50);
129-
}
130-
131-
void chime(){
132-
blurp4();
133-
}
134-
135-
void soundalarm(){
136-
for(int i=0; i<6; i++){
137-
blurp6();
138-
delay(50);
139-
}
140-
}
141-
142-
#else
7+
// #ifdef ESP8266
8+
9+
// #include <ESP8266_Tones.h> // https://github.com/Mottramlabs/ESP8266-Tone-Generator
10+
// #include <Tone_Pitches.h>
11+
// ESP8266_Tones BUZZER_TONE(BUZ_PIN);
12+
// char szBuf[128]; // serial buffer seems to be only 128 bytes on ESP, only 64 on ATmega
13+
14+
// #include <MmlMusicPWM.h> // requires #include <MmlBUZZER_MUSIC.h>
15+
// // define the pin used and initialize a MusicEngine object
16+
// MmlMusicPWM BUZZER_MUSIC(BUZ_PIN);
17+
18+
// bool init_buzzer(){
19+
// pinMode(BUZ_PIN,OUTPUT);
20+
// }
21+
22+
// void soundSiren(int nTimes=10)
23+
// {
24+
// for(int nLoop=0; nLoop<nTimes; nLoop++)
25+
// {
26+
// for(int nFreq=100; nFreq<2000; nFreq+=10)
27+
// {
28+
// BUZZER_MUSIC.tone(nFreq);
29+
// delay(1);
30+
// }
31+
// for(int nFreq=2000; nFreq>100; nFreq-=10)
32+
// {
33+
// BUZZER_MUSIC.tone(nFreq);
34+
// delay(1);
35+
// }
36+
// }
37+
// }
38+
39+
// void soundNoise(int nLength=30)
40+
// {
41+
// srand(analogRead(A0));
42+
// for(int nLoop=0; nLoop<nLength; nLoop++)
43+
// {
44+
// for(int nTimes=1; nTimes<max(400-nLoop*5,0); nTimes++)
45+
// {
46+
// BUZZER_MUSIC.tone(random(100, 2000));
47+
// delay(1);
48+
// }
49+
// BUZZER_MUSIC.noTone();
50+
// delay(max(200-nLoop*5,0));
51+
// }
52+
// }
53+
54+
// void soundNoise2(int nLength=20)
55+
// {
56+
// srand(analogRead(A0));
57+
// for(int nLoop=0; nLoop<nLength; nLoop++)
58+
// {
59+
// for(int nTimes=1; nTimes<100; nTimes++)
60+
// {
61+
// BUZZER_MUSIC.tone(random(100, 2000));
62+
// delay(1);
63+
// }
64+
// delay(100);
65+
// }
66+
// BUZZER_MUSIC.noTone();
67+
// }
68+
69+
// void soundNoise3(int nLength=5)
70+
// {
71+
// srand(analogRead(A0));
72+
// for(int nLoop=0; nLoop<nLength; nLoop++)
73+
// {
74+
// for(int nTimes=1; nTimes<200; nTimes++)
75+
// {
76+
// BUZZER_MUSIC.tone(random(100, 2000));
77+
// delay(10);
78+
// }
79+
// delay(20);
80+
// }
81+
// BUZZER_MUSIC.noTone();
82+
// }
83+
84+
// void testsounds() {
85+
// // put your setup code here, to run once:
86+
// BUZZER_MUSIC.play("T240 L16 O8 r1 CDEDC"); // give a short blurp
87+
// // soundSiren(5);
88+
// BUZZER_MUSIC.play("T240 L32 O8 r1 GDECBADGECDEDCr2GDECBADGECDEDCr1GDECBADGECDEDC"); // play a different noise
89+
// // soundNoise();
90+
// // delay(500);
91+
// // soundNoise2();
92+
// // delay(500);
93+
// // soundNoise3();
94+
// BUZZER_MUSIC.play("T240 L2 O2 r1 CDCECBrCDCDCD O1 r CDCDCDrCDCECB O0 r CDCDCDrCDCECB"); // play a different noise
95+
// }
96+
97+
// void blurp() {
98+
// BUZZER_MUSIC.play("V10 T240 L16 O8 CDEDC"); // give a short blurp
99+
// }
100+
101+
// void blurp2() {
102+
// BUZZER_MUSIC.play("T240 L16 O8 r1 CDEDC"); // give a short blurp
103+
// }
104+
105+
// void blurp3(){
106+
// BUZZER_MUSIC.play_P(PSTR("T240 O4 L64 AB>C, T240 O4 L32 CBA V0 A \0\0")); // give a short beep
107+
// }
108+
109+
// void blurp4(){
110+
// BUZZER_MUSIC.play("T240 O8 E64"); // give a short beep
111+
// }
112+
113+
// void blurp5(){
114+
// BUZZER_MUSIC.play("V20 T240 O8 G64\0\0"); // give a short beep
115+
// // BUZZER_MUSIC.play("T240 O8 G64\0\0"); // give a short beep
116+
// }
117+
118+
// void blurp6(){
119+
// BUZZER_MUSIC.play("V5 T250 L64 O7 B");
120+
// }
121+
122+
// void playBlurpA(){
123+
// blurp5();
124+
// delay(50);
125+
// blurp5();
126+
// delay(50);
127+
// blurp5();
128+
// delay(50);
129+
// }
130+
131+
// void chime(){
132+
// blurp4();
133+
// }
134+
135+
// void soundalarm(){
136+
// for(int i=0; i<6; i++){
137+
// blurp6();
138+
// delay(50);
139+
// }
140+
// }
141+
142+
// #else
143143

144144
// #include <Tone32.h>
145145
#include "pitches.h"
@@ -255,6 +255,4 @@ void soundalarm(){
255255
delay(500);
256256
}
257257

258-
#endif
259-
260-
#endif
258+
#endif

‎definitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
//
3+
// SPI MOSI MISO SCLK CS
4+
// VSPI GPIO 23 GPIO 19 GPIO 18 GPIO 5
5+
// HSPI GPIO 13 GPIO 12 GPIO 14 GPIO 15
26

37
#define ESP32BASICUSB
48

‎max31855.h

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#ifndef max31855_h
22
#define max31855_h
33

4-
// #include "MAX31855.h" // by Rob Tillaart Library Manager (NO HSPI!!)
5-
#include "Adafruit_MAX31855.h" // Seperate calls for spiread for each function, no raw bit cache!
6-
#include <ktypelinear.h>
7-
// #include <quickstats.h> // @todo test quickstats, add child class for container
8-
// #include <Statistics.h> // https://github.com/provideyourown/statistics
9-
#include <Average.h>
10-
#include <number_format.h>
4+
#define DEBUG
115

126
// NODEMCU hspi
137
// HW scl D5 14
@@ -16,10 +10,27 @@
1610
// HW cs D8 15
1711

1812
// #define MAXDO 5 // HWMISO
19-
#define MAXCS 15 // 2
20-
#define MAXCLK 14 // HWSLK
21-
#define MAXMISO 13
22-
Adafruit_MAX31855 tc(MAXCLK,MAXCS,MAXMISO);
13+
// #define MAXCS 15 // 2
14+
// #define MAXCLK 14 // HWSLK
15+
// #define MAXMISO 13
16+
17+
#define USE_max6675
18+
19+
#ifdef USE_max6675
20+
#include "max6675.h"
21+
22+
MAX6675 tc(MAX_SCK,MAX_CS,MAX_SDO);
23+
#else
24+
// #include "MAX31855.h" // by Rob Tillaart Library Manager (NO HSPI!!)
25+
#include "Adafruit_MAX31855.h" // Seperate calls for spiread for each function, no raw bit cache!
26+
Adafruit_MAX31855 tc(MAX_SCK,MAX_CS,MAX_SDO);
27+
#endif
28+
29+
#include <ktypelinear.h>
30+
// #include <quickstats.h> // @todo test quickstats, add child class for container
31+
// #include <Statistics.h> // https://github.com/provideyourown/statistics
32+
#include <Average.h>
33+
#include <number_format.h>
2334

2435
// Adafruit_MAX31855 tc(14,15,12);
2536

@@ -109,11 +120,27 @@ float correctKType(){
109120
currentTempCorr = correctedCelsius(tcmv,internalTemp);
110121
}
111122

123+
float readInternal(){
124+
#ifdef USE_max6675
125+
return 0;
126+
#else
127+
return tc.readInternal();
128+
#endif
129+
}
130+
131+
uint8_t readError(){
132+
#ifdef USE_max6675
133+
return 0;
134+
#else
135+
return tc.readError();
136+
#endif
137+
}
138+
112139
// @todo better average library, lerp etc
113140
void ReadCurrentTempAvg()
114141
{
115-
int status = tc.readError();
116-
float internal = tc.readInternal();
142+
int status = readError();
143+
float internal = readInternal();
117144
if(useInternal) currentTempAvg += internal + tempOffset;
118145
else currentTempAvg += tc.readCelsius() + tempOffset;
119146
avgReadCount++;
@@ -131,14 +158,14 @@ void ReadCurrentTempAvg()
131158
// Read the temp probe
132159
void ReadCurrentTemp()
133160
{
134-
lastTCStatus = tc.readError();
161+
lastTCStatus = readError();
135162
#ifdef DEBUG
136163
// Serial.print("tc status: ");
137164
// Serial.println( status );
138165
#endif
139166
if(useInternal){
140167
// use internal cj as real temp, useful for testing without tc or monitoring pcb etc
141-
internalTemp = tc.readInternal();
168+
internalTemp = readInternal();
142169
currentTemp = internalTemp + tempOffset;
143170
}
144171
else {
@@ -207,8 +234,8 @@ void updateDevVars(){
207234
}
208235

209236
void updateAltTemps(){
210-
internalTemp = tc.readInternal();
211-
lastTCStatus = tc.readError();
237+
internalTemp = readInternal();
238+
lastTCStatus = readError();
212239
}
213240

214241

@@ -222,7 +249,7 @@ void updateTemps(){
222249
// if(updateLock) return;
223250
// digitalWrite(0,LOW); // fixes DC left HIGH and data clocked to max ic causing screen artifacts.
224251
delay(TCinterval); // stabilizes temperatures ????
225-
internalTemp = tc.readInternal();
252+
internalTemp = readInternal();
226253
ReadCurrentTemp();
227254
if(!useAveraging)updateDevVars();
228255
// Serial.println(currentTemp);
@@ -312,17 +339,22 @@ else tft.setTextColor( YELLOW, BLACK );
312339

313340
void initTC(){
314341
// Start up the MAX31855
315-
bool res = tc.begin();
342+
bool res;
343+
#ifdef USE_max6675
344+
res = true;
345+
#else
346+
res = tc.begin();
347+
#endif
316348
// if(!res) add check now, see commits
317349
delay(200);
318-
tc.readError();
350+
readError();
319351
// check for sanity
320352
Serial.println("[TC] MAX31855 Thermocouple Begin...");
321353
if(!TCSanityCheck()) Serial.println("[ERROR] Status: "+ getTcStatus());
322354

323355
#ifdef DEBUG
324356
printTC();
325-
// Serial.println("[TC] "+(String)round(tc.readInternal()));
357+
// Serial.println("[TC] "+(String)round(readInternal()));
326358
// Serial.println("[TC] "+(String)round(tc.readCelsius()));
327359
// Serial.println("[TC] "+(String)round(readFahrenheit()));
328360
#endif

‎mqtt.h

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ WiFiClient espClient;
3232

3333
PubSubClient client(espClient);
3434

35-
bool debug_mqtt = false;
35+
bool debug_mqtt = true;
3636
bool debug_mqtt_json = false;
3737
const char* clientID = "";
3838

3939
bool mqttconnected = false;
4040

4141
long lastReconnectAttempt = 0;
42-
uint32_t mqttretry = 10000;
42+
uint32_t mqttretry = 5000;
4343

4444
void MQTTGetErrorMessage(){
4545
// Possible values for client.state()
@@ -130,7 +130,8 @@ bool process_MQTT(){
130130
}
131131
if(!client.connected()){
132132
mqttconnected = false;
133-
Logger.println("[MQTT] client not connected");
133+
Logger.print("[MQTT] client not connected => ");
134+
Logger.println(client.state());
134135
MQTTreconnect(); // @todo throttle
135136
return false;
136137
}
@@ -140,16 +141,26 @@ bool process_MQTT(){
140141

141142
void init_MQTT(){
142143
if(!wifiIsConnected()) return;
144+
if(clientID == ""){
145+
Logger.println("[MQTT] clientID not set");
146+
// clientID = getHostname();
147+
}
143148
client.setServer(mqtt_server_ip, mqtt_server_port);
149+
150+
// MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds. Override with setSocketTimeout()
151+
client.setSocketTimeout(30); // #define MQTT_SOCKET_TIMEOUT 15
152+
// MQTT_KEEPALIVE : keepAlive interval in Seconds. Override with setKeepAlive()
153+
client.setKeepAlive(10); // #define MQTT_KEEPALIVE 15
154+
144155
client.setCallback(MQTTcallback);
145156
if (client.connect(clientID)){
146157
mqttconnected = true;
147-
Logger.println("[MQTT] connected to " + (String)mqtt_server_ip);
158+
Logger.println("[MQTT] connected to " + (String)mqtt_server_ip + " as " + clientID);
148159
}
149160
else Logger.println("[MQTT] init failed to connect to " + (String)mqtt_server_ip);
150161
client.setBufferSize(_JSONSIZE);
151162
// client.subscribe("CMD");
152-
client.subscribe("ESP_env_c/CMD");
163+
// client.subscribe("ESP_env_c/CMD");
153164
process_MQTT();
154165
// jsondata = pubjson.to<JsonArray>();
155166
// jsondata = pubjson.createNestedArray();
@@ -307,19 +318,37 @@ void MQTT_pub(String topic, String sensor, String value){
307318
}
308319
#endif
309320

310-
// todo
311-
// add free heap
312-
void MQTT_pub_device(){
321+
322+
#ifdef ESP8266
323+
#define ESP_getChipId() ESP.getChipId()
324+
#elif defined(ESP32)
325+
#define ESP_getChipId() (uint32_t)ESP.getEfuseMac()
326+
#endif
327+
328+
void MQTT_pub_device(bool verbose){
313329
if(!mqttconnected)return;
314330
if(debug_mqtt) Logger.println("[MQTT] Publish Device");
315331
MQTT_pub("device","uptime_s",(String)(millis()/1000));
316332
MQTT_pub("device","rssi",(String)getRSSIasQuality());
317333
MQTT_pub("device","heap",(String)ESP.getFreeHeap());
334+
if(verbose){
335+
// MQTT_pub("device","ip",(String)ESP.getFreeHeap());
336+
// MQTT_pub("device","hostname",(String)ESP.getFreeHeap());
337+
MQTT_pub("device","ChipType",(String)ESP.getChipModel());
338+
MQTT_pub("device","chipID",(String)ESP_getChipId());
339+
MQTT_pub("device","ESPver",(String)ESP.getSdkVersion());
340+
MQTT_pub("device","chipCores",(String)ESP.getChipCores());
341+
MQTT_pub("device","chipRev",(String)ESP.getChipRevision());
342+
}
318343
// MQTT_pub("device","hall",(String)hallRead());
319344
#ifdef ESP32
320-
MQTT_pub("device","temp",(String)temperatureRead());
345+
// MQTT_pub("device","temp",(String)temperatureRead());
321346
#endif
322347
MQTT_pub_send("device");
323348
}
324349

350+
void MQTT_pub_device(){
351+
MQTT_pub_device(false);
352+
}
353+
325354
#endif

‎neoindicator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Adafruit_NeoPixel ind = Adafruit_NeoPixel();
4343
// mediumvioletred #C71585 rgb(199,21,133)
4444

4545
uint16_t INDBRIGHTNESS = 60;
46-
int INDNUMPIXELS = 2;
46+
int INDNUMPIXELS = 4;
4747
#define INDPIXELSTYPE NEO_GRB + NEO_KHZ800
4848

4949
bool INDPINRESET = false;
@@ -55,7 +55,7 @@ void init_indicator(uint16_t pin){
5555
// Adafruit_NeoPixel
5656
// strip = ind;
5757
ind.setPin(pin);
58-
ind.setBrightness(255);
58+
ind.setBrightness(100);
5959
ind.updateLength(INDNUMPIXELS);
6060
ind.updateType(NEO_GRB + NEO_KHZ800);
6161
ind.begin();

‎ota.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void startOTA(){
5757
type = "filesystem";
5858
}
5959
otastarted = true;
60-
Logger.println("\n[OTA] onStart " + type);
60+
// Logger.println("\n[OTA] onStart " + type);
6161
Serial.println("\n[OTA] onStart " + type);
6262
});
6363

0 commit comments

Comments
 (0)
Please sign in to comment.