Skip to content

Commit

Permalink
Bump version to 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrethomas committed Nov 29, 2019
1 parent ae2dd4b commit 3796d62
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
72 changes: 72 additions & 0 deletions examples/BlinkSendCommand/BlinkSendCommand.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
BlinkRelay.ino - Example for TasmotaSlave receiving the FUNC_EVERY_SECOND
callback and respond by toggling the LED as configured.
This example also extends sending commands back to the
Tasmota device by which could be any command normally
executed from the console but in this particular example
we just use a simple publish command.
Copyright (C) 2019 Andre Thomas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <Arduino.h>
#include <TasmotaSlave.h>

TasmotaSlave slave(&Serial);

bool ledstate = false;

/*******************************************************************\
* Function which will be called when Tasmota sends a
* FUNC_EVERY_SECOND command
\*******************************************************************/

void user_FUNC_EVERY_SECOND(void)
{
if (ledstate) {
ledstate = false;
digitalWrite(LED_BUILTIN, LOW);
} else {
ledstate = true;
digitalWrite(LED_BUILTIN, HIGH);
}
if (ledstate) {
slave.ExecuteCommand((char*)"publish tele/mytopic/power on");
} else {
slave.ExecuteCommand((char*)"publish tele/mytopic/power off");
}
}

/*******************************************************************\
* Normal setup() function for Arduino to configure the serial port
* speed (which should match what was configured in Tasmota) and
* attach any callback functions associated with specific requests
* or commands that are sent by Tasmota.
\*******************************************************************/

void setup() {
// Configure serial port
Serial.begin(57600);
// We're going to use the builtin LED so lets configure the pin as OUTPUT
pinMode(LED_BUILTIN, OUTPUT);
// Attach the callback function which will be called when Tasmota requests it
slave.attach_FUNC_EVERY_SECOND(user_FUNC_EVERY_SECOND);
}

void loop() {
// Call the slave loop function every so often to process incoming requests
slave.loop();
}
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SendTele KEYWORD2
waitforbytes KEYWORD2
ProcessSend KEYWORD2
ProcessCommand KEYWORD2
ExecuteCommand KEYWORD2
loop KEYWORD2

#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TasmotaSlave",
"version": "0.0.1",
"version": "0.0.2",
"keywords": [
"serial", "io", "TasmotaSlave"
],
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=TasmotaSlave
version=0.0.1
version=0.0.2
author=Andre Thomas
maintainer=Andre Thomas <[email protected]
maintainer=Andre Thomas <[email protected]>
sentence=TasmotaSlave Driver Library for Arduino
paragraph=
category=Signal Input/Output
Expand Down
10 changes: 10 additions & 0 deletions src/TasmotaSlave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ void TasmotaSlave::SendTele(char *data)
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::ExecuteCommand(char *cmnd)
{
SendCommand(CMND_EXECUTE_CMND, strlen(cmnd));
serial->write(char(PARAM_DATA_START));
for (uint8_t idx = 0; idx < strlen(cmnd); idx++) {
serial->write(cmnd[idx]);
}
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::loop(void)
{
if (serial->available()) {
Expand Down
4 changes: 3 additions & 1 deletion src/TasmotaSlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* TasmotaSlave Configuration Defaults
\*************************************************/

#define TASMOTA_SLAVE_LIB_VERSION 20191101
#define TASMOTA_SLAVE_LIB_VERSION 20191129

/*************************************************\
* TasmotaSlave Command definitions
Expand All @@ -41,6 +41,7 @@
#define CMND_FUNC_EVERY_100_MSECOND 0x04
#define CMND_SLAVE_SEND 0x05
#define CMND_PUBLISH_TELE 0x06
#define CMND_EXECUTE_CMND 0x07

/*************************************************\
* TasmotaSlave Parameter defintions
Expand Down Expand Up @@ -88,6 +89,7 @@ class TasmotaSlave {
// Used internally to decode and process incoming commands from the Tasmota device
void ProcessCommand(void);
// Main slave loop which needs to be serviced occasionally to process incoming requests
void ExecuteCommand(char *cmnd);
void loop(void);
private:
HardwareSerial *serial;
Expand Down

0 comments on commit 3796d62

Please sign in to comment.