Merge pull request #1 from arendst/development

pull from Sonoff-Tasmota
This commit is contained in:
Andrzej Raczkowski 2019-01-22 12:17:29 +01:00 committed by GitHub
commit 29002d7ec2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 142 additions and 77 deletions

View File

@ -41,7 +41,7 @@ If you want to compile Sonoff-Tasmota yourself keep in mind the following:
- Only Flash Mode **DOUT** is supported. Do not use Flash Mode DIO / QIO / QOUT as it might seem to brick your device. See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips) for background information.
- Sonoff-Tasmota uses a 1M linker script WITHOUT spiffs **1M (no SPIFFS)** for optimal code space. If you compile using ESP/Arduino library 2.3.0 then download the provided new linker script to your Arduino IDE or Platformio base folder. Later version of ESP/Arduino library already contain the correct linker script. See [Wiki > Prerequisite](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite).
- To make compile time changes to Sonoff-Tasmota it can use the ``user_config_override.h`` file. It assures keeping your settings when you download and compile a new version. To use ``user_config.override.h`` you will have to make a copy of the provided ``user_config.override_sample.h`` file and add your setting overrides. To enable the override file you will need to use a compile define as documented in the ``user_config_override_sample.h`` file.
- To make compile time changes to Sonoff-Tasmota it can use the ``user_config_override.h`` file. It assures keeping your settings when you download and compile a new version. To use ``user_config.override.h`` you will have to make a copy of the provided ``user_config_override_sample.h`` file and add your setting overrides. To enable the override file you will need to use a compile define as documented in the ``user_config_override_sample.h`` file.
### Version Information
- Sonoff-Tasmota provides all (Sonoff) modules in one file and starts with module Sonoff Basic.

View File

@ -1,7 +1,12 @@
/* 6.4.1.9 20190115
/* 6.4.1.10 20190121
* Fix Hass discovery of MHZ19(B) sensors (#4992)
*
* 6.4.1.9 20190115
* Add support for Mi LED Desk Lamp with rotary switch (#4887)
* Fix mDNS addService (#4938)
* Fix mDNS addService (#4938, #4951)
* Fix allowable MAX_RULE_VARS to 16 (#4933)
* Add (S)SerialSend3 escape sequence \x to allow hexadecimal byte value (#3560, #4947)
* Add SerialBridge command SSerialSend5 <hexdata>
*
* 6.4.1.8 20190107
* Change sonoff_template.h layout regarding optional module flags like ADC0

View File

@ -92,6 +92,7 @@
#define D_JSON_MAC "Mac"
#define D_JSON_MASK "Mask"
#define D_JSON_MINIMAL "minimal"
#define D_JSON_MODEL "Model"
#define D_JSON_NO "No"
#define D_JSON_NOISE "Noise"
#define D_JSON_NONE "None"

View File

@ -271,9 +271,7 @@ struct SYSCFG {
uint8_t ws_color[4][3]; // 475
uint8_t ws_width[3]; // 481
myio my_gp; // 484
byte free_495[1]; // 495
uint8_t test_step; // 495
uint16_t light_pixels; // 496
uint8_t light_color[5]; // 498
uint8_t light_correction; // 49D

View File

@ -1051,7 +1051,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
Serial.printf("%s", Unescape(dataBuf, &dat_len)); // "Hello\f"
}
else if (5 == index) {
SerialSendRaw(RemoveSpace(dataBuf)); // "AA004566"
SerialSendRaw(RemoveSpace(dataBuf)); // "AA004566" as hex values
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
}
@ -1427,7 +1427,7 @@ void ExecuteCommandPower(byte device, byte state, int source)
interlock_mutex = 0;
}
}
if ( Settings.flag.interlock && !interlock_mutex && !Settings.flag3.split_interlock) { //execute regular interlock-mode as interlock-split is off
if ( Settings.flag.interlock && !interlock_mutex && !Settings.flag3.split_interlock) { //execute regular interlock-mode as interlock-split is off
interlock_mutex = 1;
for (byte i = 0; i < devices_present; i++) {
power_t imask = 1 << i;
@ -2445,12 +2445,14 @@ void setup(void)
Settings.rule_enabled = 0; // Disable all rules
}
if (RtcReboot.fast_reboot_count > 4) { // Restarted 5 times
Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic
// Settings.last_module = SONOFF_BASIC;
for (byte i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
}
}
if (RtcReboot.fast_reboot_count > 5) { // Restarted 6 times
Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic
// Settings.last_module = SONOFF_BASIC;
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcReboot.fast_reboot_count);
AddLog(LOG_LEVEL_DEBUG);
}

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06040109
#define VERSION 0x0604010A
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"

View File

@ -210,10 +210,12 @@ char* Unescape(char* buffer, uint16_t* size)
{
uint8_t* read = (uint8_t*)buffer;
uint8_t* write = (uint8_t*)buffer;
uint16_t start_size = *size;
uint16_t end_size = *size;
int16_t start_size = *size;
int16_t end_size = *size;
uint8_t che = 0;
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size);
while (start_size > 0) {
uint8_t ch = *read++;
start_size--;
@ -235,6 +237,14 @@ char* Unescape(char* buffer, uint16_t* size)
case 's': che = ' '; break; // 20 Space
case 't': che = '\t'; break; // 09 Horizontal tab
case 'v': che = '\v'; break; // 0B Vertical tab
case 'x': {
uint8_t* start = read;
che = (uint8_t)strtol((const char*)read, (char**)&read, 16);
start_size -= (uint16_t)(read - start);
end_size -= (uint16_t)(read - start);
break;
}
case '"': che = '\"'; break; // 22 Quotation mark
// case '?': che = '\?'; break; // 3F Question mark
default : {
che = chi;
@ -247,6 +257,9 @@ char* Unescape(char* buffer, uint16_t* size)
}
}
*size = end_size;
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size);
return buffer;
}
@ -511,7 +524,7 @@ void ModuleGpios(myio *gp)
memcpy_P(&src, &kModules[Settings.module].gp, sizeof(mycfgio));
// 11 85 00 85 85 00 00 00 15 38 85 00 00 81
// AddLogSerial(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
if (i < 6) {
@ -526,7 +539,7 @@ void ModuleGpios(myio *gp)
}
// 11 85 00 85 85 00 00 00 00 00 00 00 15 38 85 00 00 81
// AddLogSerial(LOG_LEVEL_DEBUG, (uint8_t *)gp, sizeof(myio));
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)gp, sizeof(myio));
}
gpio_flag ModuleFlag()
@ -1197,9 +1210,9 @@ void AddLog_P(byte loglevel, const char *formatP, const char *formatP2)
AddLog(loglevel);
}
void AddLogSerial(byte loglevel, uint8_t *buffer, int count)
void AddLogBuffer(byte loglevel, uint8_t *buffer, int count)
{
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_RECEIVED));
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
for (int i = 0; i < count; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer++));
}
@ -1208,7 +1221,7 @@ void AddLogSerial(byte loglevel, uint8_t *buffer, int count)
void AddLogSerial(byte loglevel)
{
AddLogSerial(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
}
void AddLogMissed(char *sensor, uint8_t misses)

View File

@ -20,7 +20,7 @@
#ifndef _USER_CONFIG_OVERRIDE_H_
#define _USER_CONFIG_OVERRIDE_H_
// force the compiler to show a warning to confirm that this file is inlcuded
// force the compiler to show a warning to confirm that this file is included
#warning **** user_config_override.h: Using Settings from this File ****
/*****************************************************************************************************\
@ -93,4 +93,4 @@ Examples :
#endif // _USER_CONFIG_OVERRIDE_H_
#endif // _USER_CONFIG_OVERRIDE_H_

View File

@ -76,6 +76,7 @@ const char kMqttCommands[] PROGMEM =
uint16_t mqtt_retry_counter = 1; // MQTT connection retry counter
uint8_t mqtt_initial_connection_state = 2; // MQTT connection messages state
bool mqtt_connected = false; // MQTT virtual connection status
bool mqtt_allowed = false; // MQTT enabled and parameters valid
/*********************************************************************************************\
* MQTT driver specific code need to provide the following functions:
@ -210,9 +211,9 @@ void MqttLoop(void)
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
boolean MqttDiscoverServer(void)
void MqttDiscoverServer(void)
{
if (!mdns_begun) { return false; }
if (!mdns_begun) { return; }
int n = MDNS.queryService("mqtt", "tcp"); // Search for mqtt service
@ -220,26 +221,21 @@ boolean MqttDiscoverServer(void)
AddLog(LOG_LEVEL_INFO);
if (n > 0) {
#ifdef MDNS_HOSTNAME
for (int i = 0; i < n; i++) {
uint8_t i = 0; // If the hostname isn't set, use the first record found.
#ifdef MDNS_HOSTNAME
for (i = n; i > 0; i--) { // Search from last to first and use first if not found
if (!strcmp(MDNS.hostname(i).c_str(), MDNS_HOSTNAME)) {
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(i).toString().c_str());
Settings.mqtt_port = MDNS.port(i);
break; // stop at the first matching record
break; // Stop at matching record
}
}
#else
// If the hostname isn't set, use the first record found.
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str());
Settings.mqtt_port = MDNS.port(0);
#endif // MDNS_HOSTNAME
#endif // MDNS_HOSTNAME
snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(i).toString().c_str());
Settings.mqtt_port = MDNS.port(i);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port);
MDNS.hostname(i).c_str(), Settings.mqtt_host, Settings.mqtt_port);
AddLog(LOG_LEVEL_INFO);
}
return n > 0;
}
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
@ -398,7 +394,7 @@ void MqttConnected(void)
{
char stopic[TOPSZ];
if (Settings.flag.mqtt_enabled) {
if (mqtt_allowed) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_CONNECTED));
mqtt_connected = true;
mqtt_retry_counter = 0;
@ -495,7 +491,19 @@ boolean MqttCheckTls(void)
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "2"));
result = true;
}
#endif
#ifdef MDNS_HOSTNAME
// If the hostname is set, check that as well.
// This lets certs with the hostname for the CN be used.
else if (EspClient.verify(fingerprint1, MDNS_HOSTNAME)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "1"));
result = true;
}
else if (EspClient.verify(fingerprint2, MDNS_HOSTNAME)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_VERIFIED "2"));
result = true;
}
#endif // MDNS_HOSTNAME
#endif // USE_MQTT_TLS_CA_CERT
}
if (!result) AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_FAILED));
EspClient.stop();
@ -508,7 +516,18 @@ void MqttReconnect(void)
{
char stopic[TOPSZ];
if (!Settings.flag.mqtt_enabled) {
mqtt_allowed = Settings.flag.mqtt_enabled;
if (mqtt_allowed) {
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
MqttDiscoverServer();
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
if (!strlen(Settings.mqtt_host) || !Settings.mqtt_port) {
mqtt_allowed = false;
}
}
if (!mqtt_allowed) {
MqttConnected();
return;
}
@ -523,12 +542,6 @@ void MqttReconnect(void)
mqtt_retry_counter = Settings.mqtt_retry;
global_state.mqtt_down = 1;
#ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY
if (!MqttDiscoverServer() && !strlen(Settings.mqtt_host)) { return; }
#endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY
char *mqtt_user = NULL;
char *mqtt_pwd = NULL;
if (strlen(Settings.mqtt_user) > 0) mqtt_user = Settings.mqtt_user;

View File

@ -99,18 +99,34 @@ boolean SerialBridgeCommand(void)
if (-1 == command_code) {
serviced = false; // Unknown command
}
else if ((CMND_SSERIALSEND == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 3)) {
if (XdrvMailbox.data_len > 0) {
else if ((CMND_SSERIALSEND == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
if (XdrvMailbox.data_len > 0) { // "Hello Tiger\n"
if (1 == XdrvMailbox.index) {
SerialBridgeSerial->write(XdrvMailbox.data, XdrvMailbox.data_len);
SerialBridgeSerial->write("\n");
}
else if (2 == XdrvMailbox.index) {
else if ((2 == XdrvMailbox.index) || (4 == XdrvMailbox.index)) { // "Hello Tiger" or "A0"
SerialBridgeSerial->write(XdrvMailbox.data, XdrvMailbox.data_len);
}
else if (3 == XdrvMailbox.index) {
else if (3 == XdrvMailbox.index) { // "Hello\f"
SerialBridgeSerial->write(Unescape(XdrvMailbox.data, &XdrvMailbox.data_len), XdrvMailbox.data_len);
}
else if (5 == XdrvMailbox.index) { // "AA004566" as hex values
char *p;
char stemp[3];
uint8_t code;
char *codes = RemoveSpace(XdrvMailbox.data);
int size = strlen(XdrvMailbox.data);
while (size > 0) {
snprintf(stemp, sizeof(stemp), codes);
code = strtol(stemp, &p, 16);
SerialBridgeSerial->write(code);
size -= 2;
codes += 2;
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
}
}

View File

@ -122,7 +122,7 @@ bool PzemRecieve(uint8_t resp, float *data)
}
}
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, len);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, len);
if (len != sizeof(PZEMCommand)) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Pzem comms timeout"));

View File

@ -143,7 +143,7 @@ void McpSend(uint8_t *data)
data[0] = MCP_START_FRAME;
data[data[1] -1] = McpChecksum(data);
// AddLogSerial(LOG_LEVEL_DEBUG_MORE, data, data[1]);
// AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]);
for (byte i = 0; i < data[1]; i++) {
Serial.write(data[i]);

View File

@ -46,7 +46,7 @@ void PzemAcEverySecond(void)
uint8_t buffer[26];
uint8_t error = PzemAcModbus->ReceiveBuffer(buffer, 10);
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
if (error) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "PzemAc response error %d"), error);

View File

@ -46,7 +46,7 @@ void PzemDcEverySecond(void)
uint8_t buffer[22];
uint8_t error = PzemDcModbus->ReceiveBuffer(buffer, 8);
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
if (error) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "PzemDc response error %d"), error);

View File

@ -70,7 +70,7 @@ enum MhzFilterOptions {MHZ19_FILTER_OFF, MHZ19_FILTER_OFF_ALLSAMPLES, MHZ19_FILT
TasmotaSerial *MhzSerial;
const char kMhzTypes[] PROGMEM = "MHZ19|MHZ19B";
const char kMhzModels[] PROGMEM = "|B";
enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET, MHZ_CMND_RANGE_1000, MHZ_CMND_RANGE_2000, MHZ_CMND_RANGE_3000, MHZ_CMND_RANGE_5000 };
const uint8_t kMhzCommands[][4] PROGMEM = {
@ -90,7 +90,6 @@ uint16_t mhz_last_ppm = 0;
uint8_t mhz_filter = MHZ19_FILTER_OPTION;
bool mhz_abc_enable = MHZ19_ABC_ENABLE;
bool mhz_abc_must_apply = false;
char mhz_types[7];
float mhz_temperature = 0;
uint8_t mhz_retry = MHZ19_RETRY_COUNT;
@ -198,7 +197,7 @@ void MhzEverySecond(void)
}
}
AddLogSerial(LOG_LEVEL_DEBUG_MORE, mhz_response, counter);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, mhz_response, counter);
if (counter < 9) {
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "MH-Z19 comms timeout"));
@ -322,19 +321,21 @@ void MhzInit(void)
void MhzShow(boolean json)
{
char types[7] = "MHZ19B"; // MHZ19B for legacy reasons. Prefered is MHZ19
char temperature[33];
dtostrfd(mhz_temperature, Settings.flag2.temperature_resolution, temperature);
GetTextIndexed(mhz_types, sizeof(mhz_types), mhz_type -1, kMhzTypes);
char model[3];
GetTextIndexed(model, sizeof(model), mhz_type -1, kMhzModels);
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, mhz_types, mhz_last_ppm, temperature);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_MODEL "\":\"%s\",\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, types, model, mhz_last_ppm, temperature);
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, mhz_last_ppm);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_CO2, mqtt_data, mhz_types, mhz_last_ppm);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, mhz_types, temperature, TempUnit());
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_CO2, mqtt_data, types, mhz_last_ppm);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, types, temperature, TempUnit());
#endif // USE_WEBSERVER
}
}

View File

@ -48,7 +48,6 @@ bool Tsl2561Read(void)
uint16_t scaledFull, scaledIr;
uint32_t full, ir;
if (Tsl.available()) {
if (Tsl.on()) {
if (Tsl.id(id)
&& Tsl2561Util::autoGain(Tsl, gain, exposure, scaledFull, scaledIr)
@ -58,7 +57,6 @@ bool Tsl2561Read(void)
tsl2561_milliLux = 0;
}
}
}
tsl2561_valid = SENSOR_MAX_MISS;
return true;
}
@ -67,9 +65,9 @@ void Tsl2561Detect(void)
{
if (tsl2561_type) { return; }
if (!Tsl.available()) {
if (I2cDevice(0x29) || I2cDevice(0x39) || I2cDevice(0x49)) {
Tsl.begin();
if (Tsl.available()) {
if (Tsl.on()) {
tsl2561_type = 1;
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, tsl2561_types, Tsl.address());
AddLog(LOG_LEVEL_DEBUG);
@ -88,7 +86,7 @@ void Tsl2561EverySecond(void)
if (tsl2561_type) {
if (!Tsl2561Read()) {
AddLogMissed(tsl2561_types, tsl2561_valid);
// if (!tsl2561_valid) { tsl2561_type = 0; }
if (!tsl2561_valid) { tsl2561_type = 0; }
}
}
}

View File

@ -62,7 +62,7 @@ boolean PmsReadData(void)
PmsSerial->readBytes(buffer, 32);
PmsSerial->flush(); // Make room for another burst
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, 32);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 32);
// get checksum ready
for (uint8_t i = 0; i < 30; i++) {

View File

@ -108,7 +108,7 @@ bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensor
// read rest (9 of 10 bytes) of message
NovaSdsSerial->readBytes(&recbuf[1], 9);
AddLogSerial(LOG_LEVEL_DEBUG_MORE, recbuf, sizeof(recbuf));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, recbuf, sizeof(recbuf));
if ( NULL != buffer ) {
// return data to buffer

View File

@ -158,7 +158,7 @@ void AzEverySecond(void)
}
} while(((millis() - start) < AZ_READ_TIMEOUT) && (counter < sizeof(az_response)) && !az_received);
AddLogSerial(LOG_LEVEL_DEBUG_MORE, az_response, counter);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, az_response, counter);
if (!az_received) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "AZ7798 comms timeout"));

View File

@ -67,6 +67,7 @@ uint8_t pn532_i2c_disable = 0;
#ifdef USE_PN532_DATA_FUNCTION
uint8_t pn532_i2c_function = 0;
uint8_t pn532_i2c_newdata[16];
uint8_t pn532_i2c_newdata_len = 0;
#endif // USE_PN532_DATA_FUNCTION
const uint8_t PROGMEM pn532_global_timeout = 10;
@ -406,7 +407,13 @@ void PN532_ScanForTag(void)
uint8_t keyuniversal[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
if (mifareclassic_AuthenticateBlock (uid, uid_len, 1, 1, keyuniversal)) {
if (mifareclassic_ReadDataBlock(1, card_data)) {
memcpy(&card_datas,&card_data,sizeof(card_data)); // Cast block 1 to a string
for (uint8_t i = 0;i < sizeof(card_data);i++) {
if ((isalpha(card_data[i])) || ((isdigit(card_data[i])))) {
card_datas[i] = char(card_data[i]);
} else {
card_datas[i] = '\0';
}
}
}
if (pn532_i2c_function == 1) { // erase block 1 of card
for (uint8_t i = 0;i<16;i++) {
@ -420,12 +427,23 @@ void PN532_ScanForTag(void)
}
}
if (pn532_i2c_function == 2) {
memcpy(&card_data,&pn532_i2c_newdata,sizeof(card_data));
if (mifareclassic_WriteDataBlock(1, card_data)) {
set_success = true;
snprintf_P(log_data, sizeof(log_data),"I2C: PN532 NFC - Data write successful");
boolean IsAlphaNumeric = true;
for (uint8_t i = 0;i < pn532_i2c_newdata_len;i++) {
if ((!isalpha(pn532_i2c_newdata[i])) || (!isdigit(pn532_i2c_newdata[i]))) {
IsAlphaNumeric = false;
}
}
if (IsAlphaNumeric) {
if (mifareclassic_WriteDataBlock(1, card_data)) {
memcpy(&card_data,&pn532_i2c_newdata,sizeof(card_data));
set_success = true;
snprintf_P(log_data, sizeof(log_data),"I2C: PN532 NFC - Data write successful");
AddLog(LOG_LEVEL_INFO);
memcpy(&card_datas,&card_data,sizeof(card_data)); // Cast block 1 to a string
}
} else {
snprintf_P(log_data, sizeof(log_data),"I2C: PN532 NFC - Data must be alphanumeric");
AddLog(LOG_LEVEL_INFO);
memcpy(&card_datas,&card_data,sizeof(card_data)); // Cast block 1 to a string
}
}
} else {
@ -512,10 +530,10 @@ boolean PN532_Command(void)
return serviced;
}
sprintf(sub_string_tmp,subStr(sub_string, XdrvMailbox.data, ",", 2));
uint8_t dlen = strlen(sub_string_tmp);
if (dlen > 15) { dlen = 15; }
memcpy(&pn532_i2c_newdata,&sub_string_tmp,dlen);
pn532_i2c_newdata[dlen] = 0x00; // Null terminate the string
pn532_i2c_newdata_len = strlen(sub_string_tmp);
if (pn532_i2c_newdata_len > 15) { pn532_i2c_newdata_len = 15; }
memcpy(&pn532_i2c_newdata,&sub_string_tmp,pn532_i2c_newdata_len);
pn532_i2c_newdata[pn532_i2c_newdata_len] = 0x00; // Null terminate the string
pn532_i2c_function = 2;
snprintf_P(log_data, sizeof(log_data),"I2C: PN532 NFC - Next scanned tag data block 1 will be set to '%s'",pn532_i2c_newdata);
AddLog(LOG_LEVEL_INFO);