Skip to content

Commit

Permalink
Edited some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
killercode committed Sep 20, 2019
1 parent 0ce4040 commit 221ee10
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 428 deletions.
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@
"terminal.integrated.env.windows": {
"PATH": "C:\\Users\\alves\\.platformio\\penv\\Scripts;C:\\Users\\alves\\.platformio\\penv;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;%SYSTEMROOT%\\System32\\OpenSSH\\;C:\\Users\\alves\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\alves\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;%SYSTEMROOT%\\System32\\OpenSSH\\;C:\\Users\\alves\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\alves\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
"PLATFORMIO_CALLER": "vscode"
}
},
// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when `editor.detectIndentation` is true.
"editor.tabSize": 4,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": true,
// When opening a file, `editor.tabSize` and `editor.insertSpaces`
// will be detected based on the file contents. Set to false to keep
// the values you've explicitly set, above.
"editor.detectIndentation": false
}
133 changes: 65 additions & 68 deletions include/Relay.h
Original file line number Diff line number Diff line change
@@ -1,74 +1,73 @@
#include<Arduino.h>
#include <Arduino.h>

/**
* @brief Relay class to easier the operations
* @note IMPORTANT: MQTT Logic is inverted!
* @retval None
*/
class Relay
class Relay
{
public:
/**
* @brief Constructor
* @param pin: pin where the relay is connected
* @param name: name for the relay
* @param state: state of the relay
* @retval Relay object
*/
Relay(int pin, String name, uint8_t state);

/**
* @brief Initialization done after construction, to permit static instances
* @retval None
*/
void init();

/// Get State
/**
* @brief Get the actual state of the relay
* @retval 1 or 0
*/
uint8_t getState();

/**
* @brief Set the state of the relay
* @note this will actually update it physically
* @param newState: new state to be set
* @retval None
*/
void setState(uint8_t newState);

/**
* @brief Get MQTT friendly state
* @note
* @retval "1" or "0"
*/
String getStringState();

/**
* @brief set MQTT friendly state
* @note
* @retval None
*/
void setStringState(String newstate);

/**
* @brief Get the relay name as a MQTT topic
* @note
* @retval mqtt topic for the device
*/
String getName();

String MQTTSwitchState();

private:
String name;
uint8_t state;
String mqttstate;

protected:
const int pin; // pin

public:
/**
* @brief Constructor
* @param pin: pin where the relay is connected
* @param name: name for the relay
* @param state: state of the relay
* @retval Relay object
*/
Relay(int pin, String name, uint8_t state);

/**
* @brief Initialization done after construction, to permit static instances
* @retval None
*/
void init();

/// Get State
/**
* @brief Get the actual state of the relay
* @retval 1 or 0
*/
uint8_t getState();

/**
* @brief Set the state of the relay
* @note this will actually update it physically
* @param newState: new state to be set
* @retval None
*/
void setState(uint8_t newState);

/**
* @brief Get MQTT friendly state
* @note
* @retval "1" or "0"
*/
String getStringState();

/**
* @brief set MQTT friendly state
* @note
* @retval None
*/
void setStringState(String newstate);

/**
* @brief Get the relay name as a MQTT topic
* @note
* @retval mqtt topic for the device
*/
String getName();

String MQTTSwitchState();

private:
String name;
uint8_t state;
String mqttstate;

protected:
const int pin; // pin
};

Relay::Relay(int p, String n, uint8_t s) : pin(p), name(n), state(s)
Expand All @@ -77,8 +76,8 @@ Relay::Relay(int p, String n, uint8_t s) : pin(p), name(n), state(s)

void Relay::init()
{
pinMode(pin, OUTPUT);
digitalWrite(pin, state); // pull-up
pinMode(pin, OUTPUT);
digitalWrite(pin, state); // pull-up
}

void Relay::setState(uint8_t newState)
Expand Down Expand Up @@ -120,7 +119,6 @@ void Relay::setStringState(String newstate)
state = LOW;
}
setState(state);

}

String Relay::MQTTSwitchState()
Expand All @@ -135,5 +133,4 @@ String Relay::MQTTSwitchState()
setState(LOW);
return "1";
}

}
42 changes: 31 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
[![Build Status](https://travis-ci.org/killercode/DomLab.svg?branch=master)](https://travis-ci.org/killercode/DomLab)

=Setting up board=
##Repository of my home automation firmwares

Programming the sketch for the ATMEGA:
I am using an arduino mega clone with a ESP8266 onboard connected to the arduino mega serial

DIP SWITCH
# Main idea
Have a serial protocol to make the firmware on ESP8266 generic enought to be able to receive identification of each sensor or actuator and subscribe the MQTT topics that are relevant to these components.

This way we should only need to configure each arduino about what components.

For each components I will create a class that will handle the naming, pin I/O and all the inherent logic, that way we only have to deal with instancianting the classes and assign them to the correct pinout and that's all the code needed to the system to work


# Setup
For the first module I will have a board mentioned above with a 8 Relay Board

To understand how to flash the arduino or the ESP we should check the following diagram

# Setting up board

**Programming the sketch for the ATMEGA:**

```DIP SWITCH
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|OFF|OFF|ON |ON |OFF|OFF|OFF|N/A|
|ON |ON |ON |ON |OFF|OFF|OFF|N/A|
RX/TX SWITCH TX00
```

**Programming the sketch for the ESP8266:**

Programming the sketch for the ESP8266:

DIP SWITCH
```DIP SWITCH
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|OFF|OFF|OFF|OFF|ON |ON |ON |N/A|
RX/TX SWITCH TX00
```

**Running ESP8266 with terminal to PC**

Running ESP8266 with terminal to PC
DIP SWITCH
```DIP SWITCH
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|OFF|OFF|OFF|OFF|ON |ON |OFF|N/A|
RX/TX SWITCH TX00
```

**Running ESP8266 <-> ATMEGA**

Running ESP8266 <-> ATMEGA
DIP SWITCH
```DIP SWITCH
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|ON |ON |ON |ON |OFF|OFF|OFF|N/A|
RX/TX SWITCH TX03
```
Loading

0 comments on commit 221ee10

Please sign in to comment.