mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
Manually merged pull request "Is dev #39
anklimov:develop from livello:is-dev -Domotics fixed -i2c bus scan -Soft reboot on most platforms (except NRF & STM32)
This commit is contained in:
@@ -512,11 +512,14 @@ void Input::onContactChanged(int newValue) {
|
|||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
if (emit) {
|
if (emit) {
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
if (getIdxField()) {
|
if (getIdxField()) { (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}",
|
||||||
(newValue)? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", getIdxField())
|
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); getIdxField())
|
||||||
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
: publishDataToDomoticz(0, emit,
|
||||||
|
"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",
|
||||||
|
getIdxField());
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
char addrstr[MQTT_TOPIC_LENGTH];
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
@@ -545,7 +548,7 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Input::onAnalogChanged(int newValue) {
|
void Input::onAnalogChanged(int newValue) {
|
||||||
debugSerial << F("IN:") << (pin) << F("=") << newValue << endl;
|
debugSerial << F("IN:") << (pin) << F("=") << newValue << endl;
|
||||||
|
|||||||
@@ -714,26 +714,6 @@ if (WiFi.status() != WL_CONNECTED)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_STM32
|
|
||||||
void softRebootFunc() {
|
|
||||||
//nvic_sys_reset();
|
|
||||||
Serial.println("not implemented");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
|
|
||||||
void (*softRebootFunc)(void) = 0;
|
|
||||||
|
|
||||||
void printCurentLanConfig();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
||||||
void softRebootFunc(){
|
|
||||||
debugSerial<<F("ESP.restart();");
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void resetHard() {
|
void resetHard() {
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
@@ -836,7 +816,7 @@ void cmdFunctionKill(int arg_cnt, char **args) {
|
|||||||
|
|
||||||
void cmdFunctionReboot(int arg_cnt, char **args) {
|
void cmdFunctionReboot(int arg_cnt, char **args) {
|
||||||
debugSerial<<F("Soft rebooting...");
|
debugSerial<<F("Soft rebooting...");
|
||||||
//// softRebootFunc();
|
softRebootFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyConfig() {
|
void applyConfig() {
|
||||||
@@ -1310,6 +1290,8 @@ void setup_main() {
|
|||||||
setupCmdArduino();
|
setupCmdArduino();
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
|
|
||||||
|
scan_i2c_bus();
|
||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
sd_card_w5100_setup();
|
sd_card_w5100_setup();
|
||||||
#endif
|
#endif
|
||||||
@@ -1339,7 +1321,7 @@ void setup_main() {
|
|||||||
//owReady = 0;
|
//owReady = 0;
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
if (net) net->idle(&owIdle);
|
if (oneWire) oneWire->idle(&owIdle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mqttClient.setCallback(mqttCallback);
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
OneWire *net = NULL;
|
OneWire *oneWire = NULL;
|
||||||
|
|
||||||
DeviceAddress *term = NULL;
|
DeviceAddress *term = NULL;
|
||||||
|
|
||||||
@@ -46,12 +46,12 @@ int owUpdate() {
|
|||||||
|
|
||||||
|
|
||||||
Serial.println(F("Searching"));
|
Serial.println(F("Searching"));
|
||||||
if (net) net->reset_search();
|
if (oneWire) oneWire->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 (oneWire && oneWire->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 (oneWire->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)) {
|
if (!memcmp(term[i], term[t_count], 8)) {
|
||||||
ifind = i;
|
ifind = i;
|
||||||
@@ -68,7 +68,7 @@ int owUpdate() {
|
|||||||
debugSerial.println();
|
debugSerial.println();
|
||||||
if (term[t_count][0] == 0x28) {
|
if (term[t_count][0] == 0x28) {
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
oneWire->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;
|
t_count++;
|
||||||
@@ -84,20 +84,20 @@ int owUpdate() {
|
|||||||
int owSetup(owChangedType owCh) {
|
int owSetup(owChangedType owCh) {
|
||||||
#ifndef OWIRE_DISABLE
|
#ifndef OWIRE_DISABLE
|
||||||
//// todo - move memory allocation to here
|
//// todo - move memory allocation to here
|
||||||
if (net) return true; // Already initialized
|
if (oneWire) return true; // Already initialized
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
||||||
net = new OneWire;
|
oneWire = new OneWire;
|
||||||
#else
|
#else
|
||||||
debugSerial.print(F("One wire setup on PIN:"));
|
debugSerial.print(F("One wire setup on PIN:"));
|
||||||
debugSerial.println(QUOTE(USE_1W_PIN));
|
debugSerial.println(QUOTE(USE_1W_PIN));
|
||||||
net = new OneWire (USE_1W_PIN);
|
oneWire = new OneWire (USE_1W_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
// Pass our oneWire reference to Dallas Temperature.
|
||||||
sensors = new DallasTemperature(net);
|
sensors = new DallasTemperature(oneWire);
|
||||||
|
|
||||||
term = new DeviceAddress[t_max];
|
term = new DeviceAddress[t_max];
|
||||||
//regs = new int [t_max];
|
//regs = new int [t_max];
|
||||||
@@ -106,17 +106,17 @@ int owSetup(owChangedType owCh) {
|
|||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
if (net->checkPresence()) {
|
if (oneWire->checkPresence()) {
|
||||||
debugSerial.println(F("DS2482-100 present"));
|
debugSerial.println(F("DS2482-100 present"));
|
||||||
net->deviceReset();
|
oneWire->deviceReset();
|
||||||
#ifdef APU_OFF
|
#ifdef APU_OFF
|
||||||
debugSerial.println(F("APU off"));
|
debugSerial.println(F("APU off"));
|
||||||
#else
|
#else
|
||||||
net->setActivePullup();
|
oneWire->setActivePullup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||||
if (net->wireReset())
|
if (oneWire->wireReset())
|
||||||
debugSerial.println(F("\tReset done"));
|
debugSerial.println(F("\tReset done"));
|
||||||
|
|
||||||
sensors->begin();
|
sensors->begin();
|
||||||
@@ -191,7 +191,7 @@ void owAdd(DeviceAddress addr) {
|
|||||||
debugSerial.println();
|
debugSerial.println();
|
||||||
if (term[t_count][0] == 0x28) {
|
if (term[t_count][0] == 0x28) {
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
oneWire->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;
|
t_count++;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ typedef void (*owChangedType) (int , DeviceAddress, float) ;
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern OneWire *net;
|
extern OneWire *oneWire;
|
||||||
|
|
||||||
extern DallasTemperature *sensors;
|
extern DallasTemperature *sensors;
|
||||||
extern DeviceAddress *term ;
|
extern DeviceAddress *term ;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
|
#include <wire.h>
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
|
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
@@ -429,5 +430,73 @@ void printUlongValueToStr(char *valstr, unsigned long value) {
|
|||||||
valstr[i]='\0';
|
valstr[i]='\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void scan_i2c_bus() {
|
||||||
|
byte error, address;
|
||||||
|
int nDevices;
|
||||||
|
|
||||||
|
debugSerial<<("Scanning...\n");
|
||||||
|
|
||||||
|
nDevices = 0;
|
||||||
|
for(address = 1; address < 127; address++ )
|
||||||
|
{
|
||||||
|
// The i2c_scanner uses the return value of
|
||||||
|
// the Write.endTransmisstion to see if
|
||||||
|
// a device did acknowledge to the address.
|
||||||
|
Wire.beginTransmission(address);
|
||||||
|
error = Wire.endTransmission();
|
||||||
|
|
||||||
|
if (error == 0)
|
||||||
|
{
|
||||||
|
debugSerial<<("\nI2C device found at address 0x");
|
||||||
|
if (address<16)
|
||||||
|
debugSerial<<("0");
|
||||||
|
debugSerial<<(address,HEX);
|
||||||
|
debugSerial<<(" !");
|
||||||
|
|
||||||
|
nDevices++;
|
||||||
|
}
|
||||||
|
else if (error==4)
|
||||||
|
{
|
||||||
|
debugSerial<<("\nUnknow error at address 0x");
|
||||||
|
if (address<16)
|
||||||
|
debugSerial<<("0");
|
||||||
|
debugSerial<<(address,HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nDevices == 0)
|
||||||
|
debugSerial<<("No I2C devices found\n");
|
||||||
|
else
|
||||||
|
debugSerial<<("done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
void softRebootFunc() {
|
||||||
|
RSTC->RSTC_CR = 0xA5000005;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NRF5) || defined (ARDUINO_ARCH_STM32)
|
||||||
|
void softRebootFunc() {
|
||||||
|
debugSerial<<"Not implemented"<<endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
void softRebootFunc(){
|
||||||
|
debugSerial<<F("ESP.restart();");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
void softRebootFunc(){
|
||||||
|
void (*RebootFunc)(void) = 0;
|
||||||
|
RebootFunc();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ GIT: https://github.com/anklimov/lighthub
|
|||||||
e-mail anklimov@gmail.com
|
e-mail anklimov@gmail.com
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#define Q(x) #x
|
#define Q(x) #x
|
||||||
#define QUOTE(x) Q(x)
|
#define QUOTE(x) Q(x)
|
||||||
#define VALUE_TO_STRING(x) #x
|
#define VALUE_TO_STRING(x) #x
|
||||||
@@ -55,3 +57,5 @@ char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
|
|||||||
void printIPAddress(IPAddress ipAddress);
|
void printIPAddress(IPAddress ipAddress);
|
||||||
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL);
|
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL);
|
||||||
void printUlongValueToStr(char *valstr, unsigned long value);
|
void printUlongValueToStr(char *valstr, unsigned long value);
|
||||||
|
void scan_i2c_bus();
|
||||||
|
void softRebootFunc();
|
||||||
|
|||||||
@@ -395,7 +395,6 @@ lib_ignore =
|
|||||||
DS2482_OneWire
|
DS2482_OneWire
|
||||||
ModbusMaster
|
ModbusMaster
|
||||||
Syslog
|
Syslog
|
||||||
Wire
|
|
||||||
EEPROM
|
EEPROM
|
||||||
ClosedCube HDC1080
|
ClosedCube HDC1080
|
||||||
SparkFun CCS811 Arduino Library
|
SparkFun CCS811 Arduino Library
|
||||||
|
|||||||
Reference in New Issue
Block a user