Skip to content

Commit

Permalink
Make option to set static IP. (#45)
Browse files Browse the repository at this point in the history
See #44.
  • Loading branch information
CelliesProjects authored Mar 29, 2020
1 parent e9eda86 commit a8fefc0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Another cool feature is support for 3 Dallas DS18B20 temperature sensors, with t
- [Connecting a ILI9341](#connecting-a-ili9341)
- [Lunar cycle night light](#lunar-cycle-night-light)
- [SmartConfig and WiFi setup](#smartconfig-and-wifi-setup)
- [DHCP or static IP](#DHCP-or-static-IP)
- [Log files](#log-files)
- [Known issues](#known-issues)
- [Libraries in the web interface](#Libraries-used-in-web-interface)
Expand All @@ -37,8 +38,7 @@ Another cool feature is support for 3 Dallas DS18B20 temperature sensors, with t
- 5 channels led dimming (common anode) through 1.22kHz PWM at 16 bit (65535 steps) resolution. The dimming control task runs at 100Hz to ensure smooth dimming.
- Lunar cycle night light.
- 50 timers per channel with a 1 minute resolution.
- Password protected web interface to control the device. (default login is user:admin password:esp32)
<br>See it in action at my [fish](https://vissen.wasietsmet.nl/) and my [salamanders](https://salamanders.wasietsmet.nl/) tank.
- Password protected web interface to control the device. (default login is user:admin password:esp32)<br>See it in action at my [fish](https://vissen.wasietsmet.nl/) and my [salamanders](https://salamanders.wasietsmet.nl/) tank.
- SNTP timekeeping with timezone support.
- 3x OneWire DS18B20 sensor support and FFat storage with a 30 day temperature history.
- SSD1306 128x64 OLED over I<sup>2</sup>C support.
Expand Down Expand Up @@ -86,20 +86,19 @@ The sensors and displays should be plug and play, except the ILI9341 when it has

#### Compile notes

- Compare your installed libraries versions against the libraries in `aquacontrol32.ino`.
- Check your device options in `deviceSetup.h` an `devicePinSetup.h`.
- Check your device options in `deviceSetup.h` and `devicePinSetup.h`.
- Source are compiled for `mhetesp32minikit` which has support for ESP_LOGX macros.
<br>This can be changed to a particular esp32 board by changing the `--board` option in the `compile.sh` and `flash.sh` scripts.
<br>Look in `~/Arduino/hardware/espressif/esp32/boards.txt` to find the relevant board desciption.
<br>`custom_DebugLevel` should be set to `esp32_none` in the `flash.sh` script for production use.
<br>When you are still testing your hardware and setup, debug level can be set to anything depending on your needs.
<br>(`esp32_info` is probably what you need, `esp32_verbose` gives the most info)

Toggle the `GIT_TAG` option in `deviceSetup.h` to enable or disable version information.
Toggle the `GIT_TAG` option in `deviceSetup.h` to enable or disable version information.
<br>Setting `GIT_TAG` to `true` makes that the Arduino IDE can no longer compile or flash your script.
<br>You then have to use the script `compile.sh` to verify your sketch and `flash.sh` to verify/upload the sketch to the controller. You might have to adjust these scripts for your particular OS.
<br>You then have to use the script `compile.sh` to verify your sketch and `flash.sh` to verify/upload the sketch to the controller. You might have to adjust these scripts for your particular OS or setup.
<br>Read [this blog post](https://wasietsmet.nl/arduino/add-git-tag-and-version-number-to-an-arduino-sketch/) to see why I choose this method.

#### Connecting a ILI9341

- Check the [Aquacontrol hardware GitHub repo](https://github.com/CelliesProjects/aquacontrol-hardware).
Expand Down Expand Up @@ -138,6 +137,15 @@ Or use SmartConfig and take note of the next couple of things.

##### Note 2: Since Android 9 only the latest Espressif app seems to work. Android apps now requires location access to probe WiFi.

#### DHCP or static IP

By default aquacontrol will get an ip address from the DHCP server.

Follow these steps to to set a static ip address:

1. Enable `SET_STATIC_IP` (set it to `true`) in `aquacontrol32.ino`.
2. Change `STATIC_IP`, `GATEWAY`, `SUBNET`, `PRIMARY_DNS` and `SECONDARY_DNS` to the desired values.

#### Log files

By default log files are not generated.
Expand Down
23 changes: 16 additions & 7 deletions aquacontrol32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
#include <Task.h> /* Install 1.0.0 https://github.com/CelliesProjects/Task */
#include "ledState.h"

const char * wifi_network = ""; /* Change your WiFi username and password before compiling! */
const char * wifi_password = ""; /* Or use https://github.com/EspressifApp/EsptouchForAndroid/releases/latest for Android phones */
/* Or use https://github.com/EspressifApp/EsptouchForIOS/releases/tag/v1.0.0 for iPhones */
const char * wifi_network = ""; /* Change your WiFi username and password before compiling! */
const char * wifi_password = ""; /* Or use https://github.com/EspressifApp/EsptouchForAndroid/releases/latest for Android phones */
/* Or use https://github.com/EspressifApp/EsptouchForIOS/releases/tag/v1.0.0 for iPhones */

#define SET_STATIC_IP false /* If SET_STATIC_IP is set to true then STATIC_IP, GATEWAY, SUBNET and PRIMARY_DNS have to be set to some sane values */

const IPAddress STATIC_IP(192, 168, 0, 60); /* This should be outside your router dhcp range! */
const IPAddress GATEWAY(192, 168, 0, 1); /* Set to your gateway ip address */
const IPAddress SUBNET(255, 255, 255, 0); /* Usually 255,255,255,0 but check in your router or pc connected to the same network */
const IPAddress PRIMARY_DNS(192, 168, 0, 30); /* Check in your router */
const IPAddress SECONDARY_DNS( 192, 168, 0, 50 ); /* Check in your router */

#include "deviceSetup.h"
#include "devicePinSetup.h"

Expand Down Expand Up @@ -251,8 +260,8 @@ const TaskHandle_t startTFT() {
NULL, /* Task input parameter */
tftTaskPriority, /* Priority of the task */
&xTftTaskHandle, /* Task handle. */
1);
return xTftTaskHandle;
1);
return xTftTaskHandle;
}

void setup()
Expand Down Expand Up @@ -289,7 +298,7 @@ void setup()
tft.begin( TFT_SPI_CLOCK );

if ( TFT_HAS_NO_MISO || tft.readcommand8( ILI9341_RDSELFDIAG ) == 0xE0 ) {
if (!startTFT()) ESP_LOGE(TAG,"Could not start TFT task.");
if (!startTFT()) ESP_LOGE(TAG, "Could not start TFT task.");
}
else ESP_LOGI( TAG, "No ILI9341 found" );

Expand Down Expand Up @@ -360,7 +369,7 @@ void setup()
OLED.drawString( 64, 20, errorffatStr );
OLED.display();
}
while (true) delay(1000); /* system is halted */;
while (true) delay(1000); /* system is halted */;
}
}

Expand Down
10 changes: 8 additions & 2 deletions oledtask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ void oledTask( void * pvParameters ) {
snprintf( content, sizeof( content ), "%.2f kB RAM", esp_get_free_heap_size() / 1024.0 );
OLED.drawString( 64, 10, content );

OLED.drawString( 64, 20, "IP: " + WiFi.localIP().toString() );
if (!WiFi.isConnected())
OLED.drawString(64, 20, "WiFi ERROR");
else
OLED.drawString( 64, 20, "IP: " + WiFi.localIP().toString() );

snprintf( content, sizeof( content ), "%i Dallas sensors", logger.sensorCount() );
OLED.drawString( 64, 30, content );
Expand All @@ -33,7 +36,10 @@ void oledTask( void * pvParameters ) {
const uint8_t BARS_BORDER = 4;
const uint8_t BARS_WIDTH = OLED.getWidth() / NUMBER_OF_CHANNELS;

OLED.drawString( 64, 0, WiFi.localIP().toString() );
if (!WiFi.isConnected())
OLED.drawString(64, 0, "WiFi ERROR");
else
OLED.drawString( 64, 0, "IP: " + WiFi.localIP().toString() );

for ( uint8_t thisChannel = 0; thisChannel < NUMBER_OF_CHANNELS; thisChannel++ ) {
uint8_t x1 = BARS_WIDTH * thisChannel + BARS_BORDER;
Expand Down
19 changes: 11 additions & 8 deletions tfttask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,17 @@ void showIPAddress() {
char buff[15];
int16_t x, y;
uint16_t w, h;
snprintf( buff, sizeof( buff ), "%s", WiFi.localIP().toString().c_str() );
tft.fillRect( networkArea.x, networkArea.y, networkArea.w, networkArea.h, TFT_BACK_COLOR );
tft.setTextSize( networkArea.fontsize );
tft.getTextBounds( buff, 0, 0, &x, &y, &w, &h);
tft.setCursor( ( networkArea.x + networkArea.w / 2 ) - w / 2,
( networkArea.y + ( networkArea.h / 2 ) - h / 2 ) );
tft.setTextColor( TFT_TEXT_COLOR, TFT_BACK_COLOR );
tft.print( buff );
if (!WiFi.isConnected())
snprintf(buff, sizeof(buff), "%s", "WiFi ERROR");
else
snprintf(buff, sizeof(buff), "%s", WiFi.localIP().toString().c_str());
tft.fillRect(networkArea.x, networkArea.y, networkArea.w, networkArea.h, TFT_BACK_COLOR);
tft.setTextSize(networkArea.fontsize);
tft.getTextBounds(buff, 0, 0, &x, &y, &w, &h);
tft.setCursor((networkArea.x + networkArea.w / 2) - w / 2,
(networkArea.y + ( networkArea.h / 2) - h / 2));
tft.setTextColor(TFT_TEXT_COLOR, TFT_BACK_COLOR);
tft.print(buff);
}

void drawSensors() {
Expand Down
11 changes: 8 additions & 3 deletions wifitask.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
void wifiTask( void * pvParameters ) {
/* trying last accesspoint */
if (SET_STATIC_IP && !WiFi.config(STATIC_IP, GATEWAY, SUBNET, PRIMARY_DNS, SECONDARY_DNS))
ESP_LOGE(TAG, "Setting static IP failed");

WiFi.mode( WIFI_STA );
WiFi.setSleep( false );

if ( wifi_network != "" ) WiFi.begin( wifi_network, wifi_password );
if (strlen(wifi_network)) {
ESP_LOGI(TAG, "Connecting to %s.", wifi_network);
WiFi.begin(wifi_network, wifi_password);
}
/* trying last accesspoint */
else WiFi.begin();

if ( xTftTaskHandle ) {
Expand Down Expand Up @@ -57,7 +63,6 @@ void wifiTask( void * pvParameters ) {

waitForWifi();

WiFi.setAutoReconnect( true );
/* We have succesfully connected */
WiFi.onEvent( WiFiEvent );
ESP_LOGI( TAG, "WiFi connected to '%s' %s %s",
Expand Down

0 comments on commit a8fefc0

Please sign in to comment.