mirror of
https://github.com/anklimov/lighthub
synced 2025-12-09 13:19:50 +03:00
refactoring. help cmd improved. Removed newline from freeMem periodical print.
This commit is contained in:
@@ -23,7 +23,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
extern PubSubClient client;
|
extern PubSubClient mqttClient;
|
||||||
|
|
||||||
Input::Input(char * name) //Constructor
|
Input::Input(char * name) //Constructor
|
||||||
{
|
{
|
||||||
@@ -121,11 +121,11 @@ void Input::Changed (int val)
|
|||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
{ //send set command
|
{ //send set command
|
||||||
if (!scmd) client.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) client.publish(emit->valuestring,scmd->valuestring);
|
if (!scmd) mqttClient.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) mqttClient.publish(emit->valuestring,scmd->valuestring);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //send reset command
|
{ //send reset command
|
||||||
if (!rcmd) client.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) client.publish(emit->valuestring,rcmd->valuestring);
|
if (!rcmd) mqttClient.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) mqttClient.publish(emit->valuestring,rcmd->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1330
lighthub/item.cpp
1330
lighthub/item.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,14 +25,14 @@ void Changed (int i, DeviceAddress addr, int val);
|
|||||||
void modbusIdle(void);
|
void modbusIdle(void);
|
||||||
void _handleHelp(int arg_cnt, char **args);
|
void _handleHelp(int arg_cnt, char **args);
|
||||||
void _kill(int arg_cnt, char **args);
|
void _kill(int arg_cnt, char **args);
|
||||||
void parseConfig();
|
void parseConfigFromParsedJSON();
|
||||||
void _loadConfig (int arg_cnt, char **args);
|
void _loadConfig (int arg_cnt, char **args);
|
||||||
int loadConfig (int arg_cnt, char **args);
|
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
||||||
void _mqttConfigReq (int arg_cnt, char **args);
|
void _mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigReq (int arg_cnt, char **args);
|
int mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigResp (char * as);
|
int mqttConfigResp (char * as);
|
||||||
void _saveConfig(int arg_cnt, char **args);
|
void _saveConfigToEEPROM(int arg_cnt, char **args);
|
||||||
void _setConfig(int arg_cnt, char **args);
|
void _setMacAddress(int arg_cnt, char **args);
|
||||||
void _getConfig(int arg_cnt, char **args);
|
void _getConfig(int arg_cnt, char **args);
|
||||||
void printBool (bool arg);
|
void printBool (bool arg);
|
||||||
void saveFlash(short n, char* str);
|
void saveFlash(short n, char* str);
|
||||||
|
|||||||
@@ -22,67 +22,74 @@ e-mail anklimov@gmail.com
|
|||||||
#include "owTerm.h"
|
#include "owTerm.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
OneWire *net = NULL;
|
OneWire *net = NULL;
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
// Pass our oneWire reference to Dallas Temperature.
|
||||||
//DallasTemperature sensors(&net);
|
//DallasTemperature sensors(&net);
|
||||||
|
|
||||||
DeviceAddress *term = NULL;
|
DeviceAddress *term = NULL;
|
||||||
//int *regs = NULL;
|
//int *regs = NULL;
|
||||||
uint16_t *wstat = NULL;
|
uint16_t *wstat = NULL;
|
||||||
DallasTemperature *sensors = NULL;
|
DallasTemperature *sensors = NULL;
|
||||||
|
|
||||||
short si=0;
|
short si = 0;
|
||||||
int t_count = 0;
|
int t_count = 0;
|
||||||
unsigned long owTimer=0;
|
unsigned long owTimer = 0;
|
||||||
|
|
||||||
owChangedType owChanged;
|
owChangedType owChanged;
|
||||||
|
|
||||||
int owUpdate()
|
int owUpdate() {
|
||||||
{
|
unsigned long finish = millis() + 5000;
|
||||||
unsigned long finish = millis() + 5000;
|
short sr;
|
||||||
short sr;
|
|
||||||
|
|
||||||
//net.setStrongPullup();
|
//net.setStrongPullup();
|
||||||
Serial.println(F("Searching"));
|
Serial.println(F("Searching"));
|
||||||
if (net) net->reset_search();
|
if (net) net->reset_search();
|
||||||
for (short i=0;i<t_count;i++) wstat[i]&=~SW_FIND; //absent
|
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||||
|
|
||||||
while (net && net->wireSearch(term[t_count])>0 && (t_count<t_max) && finish > millis ())
|
while (net && net->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||||
{ short ifind=-1;
|
short ifind = -1;
|
||||||
if (net->crc8(term[t_count], 7) == term[t_count][7])
|
if (net->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||||
{
|
for (short i = 0; i < t_count; i++)
|
||||||
for (short i=0;i<t_count;i++) if (!memcmp(term[i],term[t_count],8)) {ifind=i;wstat[i]|=SW_FIND;
|
if (!memcmp(term[i], term[t_count], 8)) {
|
||||||
Serial.print(F(" Node:"));PrintBytes(term[t_count],8);Serial.println(F(" alive"));
|
ifind = i;
|
||||||
break;}; //alive
|
wstat[i] |= SW_FIND;
|
||||||
if (ifind<0 && sensors)
|
Serial.print(F(" Node:"));
|
||||||
{
|
PrintBytes(term[t_count], 8);
|
||||||
wstat[t_count]=SW_FIND; //Newly detected
|
Serial.println(F(" alive"));
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
break;
|
||||||
Serial.println();
|
}; //alive
|
||||||
if (term[t_count][0]==0x28)
|
if (ifind < 0 && sensors) {
|
||||||
{
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
|
Serial.print(F("dev#"));
|
||||||
|
Serial.print(t_count);
|
||||||
|
Serial.print(F(" Addr:"));
|
||||||
|
PrintBytes(term[t_count], 8);
|
||||||
|
Serial.println();
|
||||||
|
if (term[t_count][0] == 0x28) {
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
net->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;}
|
t_count++;
|
||||||
}//if
|
}
|
||||||
} //while
|
}//if
|
||||||
|
} //while
|
||||||
|
|
||||||
Serial.print(F("1-wire count: "));
|
Serial.print(F("1-wire count: "));
|
||||||
Serial.println(t_count);
|
Serial.println(t_count);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owSetup(owChangedType owCh) {
|
int owSetup(owChangedType owCh) {
|
||||||
//// todo - move memory allocation to here
|
//// todo - move memory allocation to here
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
||||||
net = new OneWire;
|
net = new OneWire;
|
||||||
#else
|
#else
|
||||||
Serial.print(F("One wire setup on PIN:"));
|
Serial.print(F("One wire setup on PIN:"));
|
||||||
Serial.println(QUOTE(USE_1W_PIN));
|
Serial.println(QUOTE(USE_1W_PIN));
|
||||||
@@ -92,110 +99,104 @@ net = new OneWire (USE_1W_PIN);
|
|||||||
|
|
||||||
|
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
// Pass our oneWire reference to Dallas Temperature.
|
||||||
sensors = new DallasTemperature (net);
|
sensors = new DallasTemperature(net);
|
||||||
|
|
||||||
term = new DeviceAddress[t_max];
|
term = new DeviceAddress[t_max];
|
||||||
//regs = new int [t_max];
|
//regs = new int [t_max];
|
||||||
wstat = new uint16_t [t_max];
|
wstat = new uint16_t[t_max];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
|
Wire.begin();
|
||||||
|
if (net->checkPresence()) {
|
||||||
|
Serial.println(F("DS2482-100 present"));
|
||||||
|
net->deviceReset();
|
||||||
|
#ifdef APU_OFF
|
||||||
|
Serial.println(F("APU off"));
|
||||||
|
#else
|
||||||
|
net->setActivePullup();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
Serial.println(F("\tChecking for 1-Wire devices..."));
|
||||||
Wire.begin();
|
if (net->wireReset())
|
||||||
if (net->checkPresence())
|
Serial.println(F("\tReset done"));
|
||||||
{
|
|
||||||
Serial.println(F("DS2482-100 present"));
|
|
||||||
net->deviceReset();
|
|
||||||
#ifdef APU_OFF
|
|
||||||
Serial.println(F("APU off"));
|
|
||||||
#else
|
|
||||||
net->setActivePullup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Serial.println(F("\tChecking for 1-Wire devices..."));
|
sensors->begin();
|
||||||
if (net->wireReset())
|
owChanged = owCh;
|
||||||
Serial.println(F("\tReset done"));
|
//owUpdate();
|
||||||
|
//Serial.println(F("\t1-w Updated"));
|
||||||
sensors->begin();
|
sensors->setWaitForConversion(false);
|
||||||
owChanged=owCh;
|
|
||||||
//owUpdate();
|
|
||||||
//Serial.println(F("\t1-w Updated"));
|
|
||||||
sensors->setWaitForConversion(false);
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
||||||
|
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sensors_loop(void)
|
int sensors_loop(void) {
|
||||||
{
|
if (!sensors) return -1;
|
||||||
if (!sensors) return -1;
|
if (si >= t_count) {
|
||||||
if (si>=t_count)
|
owUpdate(); //every check circle - scan for new devices
|
||||||
{
|
si = 0;
|
||||||
owUpdate(); //every check circle - scan for new devices
|
return 8000;
|
||||||
si=0;
|
}
|
||||||
return 8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
int t;
|
int t;
|
||||||
switch (term[si][0]){
|
switch (term[si][0]) {
|
||||||
|
|
||||||
case 0x28: // Thermomerer
|
case 0x28: // Thermomerer
|
||||||
t=sensors->getTempC(term[si]);//*10.0;
|
t = sensors->getTempC(term[si]);//*10.0;
|
||||||
//Serial.println("o");
|
//Serial.println("o");
|
||||||
if (owChanged) owChanged(si,term[si],t);
|
if (owChanged) owChanged(si, term[si], t);
|
||||||
sensors->requestTemperaturesByAddress(term[si]);
|
sensors->requestTemperaturesByAddress(term[si]);
|
||||||
si++;
|
si++;
|
||||||
return 2500;
|
return 2500;
|
||||||
|
|
||||||
// default
|
// default
|
||||||
// return sensors_ext();
|
// return sensors_ext();
|
||||||
} //switch
|
} //switch
|
||||||
|
|
||||||
|
|
||||||
si++;
|
si++;
|
||||||
return check_circle;
|
return check_circle;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void owLoop()
|
void owLoop() {
|
||||||
|
if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
||||||
{
|
|
||||||
if (millis() >=owTimer) owTimer=millis()+sensors_loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owFind(DeviceAddress addr)
|
int owFind(DeviceAddress addr) {
|
||||||
{
|
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
||||||
for (short i=0;i<t_count;i++) if (!memcmp(term[i],addr,8)) return i;//find
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void owAdd (DeviceAddress addr)
|
void owAdd(DeviceAddress addr) {
|
||||||
{
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
wstat[t_count]=SW_FIND; //Newly detected
|
memcpy(term[t_count], addr, 8);
|
||||||
memcpy (term[t_count],addr,8);
|
//term[t_count]=addr;
|
||||||
//term[t_count]=addr;
|
|
||||||
|
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
Serial.print(F("dev#"));
|
||||||
Serial.println();
|
Serial.print(t_count);
|
||||||
if (term[t_count][0]==0x28)
|
Serial.print(F(" Addr:"));
|
||||||
{
|
PrintBytes(term[t_count], 8);
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
Serial.println();
|
||||||
net->setStrongPullup();
|
if (term[t_count][0] == 0x28) {
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
}
|
net->setStrongPullup();
|
||||||
t_count++;
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
|
}
|
||||||
|
t_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
; megaatmega2560
|
megaatmega2560
|
||||||
due
|
; due
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
|
|||||||
Reference in New Issue
Block a user