Skip to content

Commit

Permalink
Merge pull request #21 from dj1ch/development
Browse files Browse the repository at this point in the history
massive overhaul
  • Loading branch information
dj1ch authored Jun 8, 2024
2 parents bb6fb8e + 850c27b commit fbead61
Show file tree
Hide file tree
Showing 18 changed files with 1,205 additions and 1,021 deletions.
4 changes: 2 additions & 2 deletions FACES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The Minigotchi has multiple faces, similar to that of the Pwnagotchi. I tried my
### (>-<) Intense

- sending frames to an AP
- sending *Pwnagotchi-like* beacon frame
- sending _Pwnagotchi-like_ beacon frame
- doing any task of some sort that may require resources

### (0-o) (o-0) Looking around
Expand All @@ -39,4 +39,4 @@ The Minigotchi has multiple faces, similar to that of the Pwnagotchi. I tried my

### (-.-) Sleeping

- switching channel
- switching channel
19 changes: 11 additions & 8 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ int Config::baud = 115200;

Here, you can adjust the baud rate, which is of course optional. Make sure your serial terminal is running at the same baud rate as the Minigotchi.

- Here, we can adjust the BSSID we listen on, and the channel we start on.
- Here, we can adjust the channel we start on.

```cpp
// define init bssid, channel
std::string Config::bssid = "fo:od:ba:be:fo:od"; // note: this used to be const* char Config::bssid = "fo:od:ba:be:fo:od";
// define init channel
int Config::channel = 1;
```

Replace the `"fo:od:ba:be:fo:od"` with your actual BSSID(in the quotations), and the `1` with the channel you prefer(not in quotations). Note that the WiFi network you're listening on should be on a specific WiFi channel anyway, each AP is on a specific one. The BSSID in question should be one of your own, assuming the Pwnagotchi is in your home it should be able to associate with your home WiFi network.
Replace the `1` with the channel you prefer(not in quotations).

- After this, we can configure our screen (Not in any version `<= 3.0.1`)

Expand All @@ -53,12 +52,16 @@ bool Config::display = false;
std::string Config::screen = "";
```

There are two different screen types available:
There are multiple different screen types available:

- `SSD1306`

- `WEMOS_OLED_SHIELD`

- `CYD`

- `T_DISPLAY_S3`

Set `bool Config::display = false;` to true, and `std::string Config::screen = "<YOUR_SCREEN_TYPE>";` to one of those screen types if your screen is supported.

**Keep in mind when you do enable a screen you are at a higher risk of your Minigotchi crashing...**
Expand Down Expand Up @@ -103,9 +106,9 @@ https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32

- Install the following dependencies with the library manager: `ArduinoJson`, `Adafruit GFX`, and your screen library(see below), etc with all their dependencies (Please install all of them for them to work correctly).

| `SSD1306` | `WEMOS_OLED_SHIELD` |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| `Adafruit SSD1306`, remove `Adafruit SSD1306 Wemos Mini OLED` if installed | `Adafruit SSD1306 Wemos Mini OLED`, remove `Adafruit SSD1306` if installed |
| `SSD1306` | `WEMOS_OLED_SHIELD` | `CYD` | `T_DISPLAY_S3` |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Adafruit SSD1306`, remove `Adafruit SSD1306 Wemos Mini OLED` if installed | `Adafruit SSD1306 Wemos Mini OLED`, remove `Adafruit SSD1306` if installed | Follow the [CYD documentation](https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/blob/main/SETUP.md), it uses a similar library much like the `T_DISPLAY_S3` | Follow the [T-Display-S3 documentation](https://github.com/Xinyuan-LilyGO/T-Display-S3/tree/main?tab=readme-ov-file#4%EF%B8%8F%E2%83%A3--arduino-ide-manual-installation), it uses a library similar to the `CYD` |

Make sure you install the correct library, they aren't the same library and if you install the wrong one it will result in the compilation failing.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

### Intro

Due to a surge in people asking for ESP32 support, I have created this fork. Fundamentally the ESP8266 and ESP32 can perform similar functions, although the ESP32 has more features, memory, computing power, etc. Development may be a bit slower as I am still working on the actual [Minigotchi](https://github.com/Pwnagotchi-Unofficial/minigotchi). As soon as this project is finished, I will start working on porting!
Due to a surge in people asking for ESP32 support, I have created this fork. Fundamentally the ESP8266 and ESP32 can perform similar functions, although the ESP32 has more features, memory, computing power, etc. We have more and more ESP32s being supported, feel free to ask me on supporting a device.

### Install guide

See the [install guide](INSTALL.md). (Not ready yet!)
See the [install guide](INSTALL.md).

### Languages

Expand Down
176 changes: 90 additions & 86 deletions minigotchi-ESP32/channel.cpp
Original file line number Diff line number Diff line change
@@ -1,120 +1,124 @@
/**
* channel.cpp: handles channel switching
*/
*/

#include "channel.h"

/** developer note:
*
* i am using the ideal 2.4 GHz channels, which are 1, 6, and 11.
* the reason for that is so we don't interfere with other devices on our frequency.
* there are probably plenty more reasons but this is a good practice for such iot devices.
* the reason for that is so we don't interfere with other devices on our
* frequency. there are probably plenty more reasons but this is a good practice
* for such iot devices.
*
*/

// same channels in config
int Channel::channelList[13] = {
Config::channels[0], Config::channels[1], Config::channels[2], Config::channels[3],
Config::channels[4], Config::channels[5], Config::channels[6], Config::channels[7],
Config::channels[8], Config::channels[9], Config::channels[10], Config::channels[11],
Config::channels[12]
};
Config::channels[0], Config::channels[1], Config::channels[2],
Config::channels[3], Config::channels[4], Config::channels[5],
Config::channels[6], Config::channels[7], Config::channels[8],
Config::channels[9], Config::channels[10], Config::channels[11],
Config::channels[12]};

void Channel::init(int initChannel) {
// start on user specified channel
delay(250);
Serial.println(" ");
Serial.print("(-.-) Initializing on channel ");
Serial.println(initChannel);
Serial.println(" ");
Display::cleanDisplayFace("(-.-)");
Display::attachSmallText("Initializing on channel " + (String) initChannel);
delay(250);
// start on user specified channel
delay(250);
Serial.println(" ");
Serial.print("(-.-) Initializing on channel ");
Serial.println(initChannel);
Serial.println(" ");
Display::cleanDisplayFace("(-.-)");
Display::attachSmallText("Initializing on channel " + (String)initChannel);
delay(250);

// switch channel
Minigotchi::monStop();
esp_err_t err = esp_wifi_set_channel(initChannel, WIFI_SECOND_CHAN_NONE);
Minigotchi::monStart();
// switch channel
Minigotchi::monStop();
esp_err_t err = esp_wifi_set_channel(initChannel, WIFI_SECOND_CHAN_NONE);
Minigotchi::monStart();

if (err == ESP_OK && initChannel == getChannel()) {
Serial.print("('-') Successfully initialized on channel ");
Serial.println(getChannel());
Display::cleanDisplayFace("('-')");
Display::attachSmallText("Successfully initialized on channel " + (String) getChannel());
delay(250);
} else {
Serial.println("(X-X) Channel initialization failed, try again?");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Channel initialization failed, try again?");
delay(250);
}
if (err == ESP_OK && initChannel == getChannel()) {
Serial.print("('-') Successfully initialized on channel ");
Serial.println(getChannel());
Display::cleanDisplayFace("('-')");
Display::attachSmallText("Successfully initialized on channel " +
(String)getChannel());
delay(250);
} else {
Serial.println("(X-X) Channel initialization failed, try again?");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Channel initialization failed, try again?");
delay(250);
}
}

void Channel::cycle() {
// get channels
int numChannels = sizeof(channelList) / sizeof(channelList[0]);
void Channel::cycle() {
// get channels
int numChannels = sizeof(channelList) / sizeof(channelList[0]);

// select a random one
int randomIndex = random(numChannels);
int newChannel = channelList[randomIndex];
// select a random one
int randomIndex = random(numChannels);
int newChannel = channelList[randomIndex];

// switch here
switchChannel(newChannel);
// switch here
switchChannel(newChannel);
}

void Channel::switchChannel(int newChannel) {
// switch to channel
delay(250);
Serial.print("(-.-) Switching to channel ");
Serial.println(newChannel);
Serial.println(" ");
Display::cleanDisplayFace("(-.-)");
Display::attachSmallText("Switching to channel " + (String) newChannel);
delay(250);
// switch to channel
delay(250);
Serial.print("(-.-) Switching to channel ");
Serial.println(newChannel);
Serial.println(" ");
Display::cleanDisplayFace("(-.-)");
Display::attachSmallText("Switching to channel " + (String)newChannel);
delay(250);

// monitor this one channel
Minigotchi::monStop();
esp_err_t err = esp_wifi_set_channel(newChannel, WIFI_SECOND_CHAN_NONE);
Minigotchi::monStart();
// monitor this one channel
Minigotchi::monStop();
esp_err_t err = esp_wifi_set_channel(newChannel, WIFI_SECOND_CHAN_NONE);
Minigotchi::monStart();

// check if the channel switch was successful
if (err == ESP_OK) {
checkChannel(newChannel);
} else {
Serial.println("(X-X) Failed to switch channel.");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Failed to switch channel.");
delay(250);
}
// check if the channel switch was successful
if (err == ESP_OK) {
checkChannel(newChannel);
} else {
Serial.println("(X-X) Failed to switch channel.");
Serial.println(" ");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Failed to switch channel.");
delay(250);
}
}

// check if the channel switch was successful
void Channel::checkChannel(int channel) {
int currentChannel = Channel::getChannel();
if (channel == currentChannel) {
Serial.print("('-') Currently on channel ");
Serial.println(currentChannel);
Display::cleanDisplayFace("('-')");
Display::attachSmallText("Currently on channel " + (String) getChannel());
Serial.println(" ");
delay(250);
} else {
Serial.print("(X-X) Channel switch to channel ");
Serial.print(channel);
Serial.println(" has failed");
Serial.print("(X-X) Currently on channel ");
Serial.print(currentChannel);
Serial.println(" instead");
Serial.println(" ");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Channel switch to " + (String) channel + " has failed");
delay(250);
}
int currentChannel = Channel::getChannel();
if (channel == currentChannel) {
Serial.print("('-') Currently on channel ");
Serial.println(currentChannel);
Display::cleanDisplayFace("('-')");
Display::attachSmallText("Currently on channel " + (String)getChannel());
Serial.println(" ");
delay(250);
} else {
Serial.print("(X-X) Channel switch to channel ");
Serial.print(channel);
Serial.println(" has failed");
Serial.print("(X-X) Currently on channel ");
Serial.print(currentChannel);
Serial.println(" instead");
Serial.println(" ");
Display::cleanDisplayFace("(X-X)");
Display::attachSmallText("Channel switch to " + (String)channel +
" has failed");
delay(250);
}
}

int Channel::getChannel() {
uint8_t primary;
wifi_second_chan_t second;
esp_wifi_get_channel(&primary, &second);
return primary;
uint8_t primary;
wifi_second_chan_t second;
esp_wifi_get_channel(&primary, &second);
return primary;
}
24 changes: 12 additions & 12 deletions minigotchi-ESP32/channel.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/**
* channel.h: header files for channel.cpp
*/
*/

#ifndef CHANNEL_H
#define CHANNEL_H

#include "minigotchi.h"
#include "config.h"
#include "display.h"
#include "minigotchi.h"
#include <WiFi.h>
#include <esp_wifi.h>

class Channel {
public:
static void init(int initChannel);
static void cycle();
static void switchChannel(int newChannel);
static int getChannel();
static void checkChannel(int channel);
static int channelList[13]; // 13 channels
static void init(int initChannel);
static void cycle();
static void switchChannel(int newChannel);
static int getChannel();
static void checkChannel(int channel);
static int channelList[13]; // 13 channels

private:
static int randomIndex;
static int numChannels;
static int currentChannel;
static int newChannel;
static int randomIndex;
static int numChannels;
static int currentChannel;
static int newChannel;
};

#endif // CHANNEL_H
Loading

0 comments on commit fbead61

Please sign in to comment.