Skip to content

Commit

Permalink
Merge pull request #645 from Jocke4f/fix_m5_listener
Browse files Browse the repository at this point in the history
Clean-up in m5atom and m5stick listeners
  • Loading branch information
josephdadams authored Feb 2, 2024
2 parents c38b1d3 + 7212073 commit ecf47c9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
7 changes: 4 additions & 3 deletions listener_clients/M5AtomMatrix-listener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ Done! Now your board is running the latest listener client firmware version. Go
# Setup your device
1. Plug the device in a power source
2. Wait for the boot animation to finish, if there is no saved AP it will start an Access Point where you can configure one.
3. Connect to the 'm5Atom-1xxxxxxx' access point via phone and go to 192.168.4.1 (or wait a bit, and captive portal page should open).
3. Connect to the 'm5Atom-XXXXXX' Access Point via phone and go to 192.168.4.1 (or wait a bit, a captive portal page should open). NB: The portal times out after 120 sec of inactivity.
4. Set your Tally Arbiter server ip by going to *"Setup"* page.
5. Go back, then go to the "Configure WiFi" page and set your WiFi credentials. The board should reboot.
6. If the connection is successful a WiFi animation and a green tick mark will show. If not a red cross will be shown and you can reboot the device to try again.

* If you need to reset WI-FI credentials. Press Atom button for 5 seconds.

Button (behind screen):
Single click - Toggle between camera number 1 to 16.
Long press 5 seconds - reset WiFi credentials.

# Troubleshooting
### macOS build error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <Preferences.h>
#define DATA_PIN_LED 27

#define SHOW_CAMERA_NUMBER_DURING_PVW_AND_PGM false

//M5 variables
PinButton btnAction(39); //the "Action" button on the device
Preferences preferences;
Expand All @@ -38,8 +40,8 @@ IPAddress stationMask = IPAddress(255, 255, 255, 0);
//Local Default Camera Number. Used for local display only - does not impact function. Zero results in a single dot displayed.
int camNumber = 0;

// Name of the device - the serial number of the listener hardware will be appended to create a unique identifier for the server.
String listenerDeviceName = "m5Atom-1";
// Name of the device - the 3 last bytes of the mac address will be appended to create a unique identifier for the server.
String listenerDeviceName = "m5Atom-";

//M5atom Access Point Password
//minimum of 8 characters
Expand Down Expand Up @@ -309,8 +311,8 @@ void setDeviceName(){
preferences.putString("deviceid", DeviceId);
preferences.end();
logger("-------------------------------------------------", "info-quiet");
logger("DeviceName:" + String(DeviceName), "info-quiet");
logger("DeviceId:" + String(DeviceId), "info-quiet");
logger("DeviceName: " + String(DeviceName), "info-quiet");
logger("DeviceId: " + String(DeviceId), "info-quiet");
logger("-------------------------------------------------", "info-quiet");
}

Expand Down Expand Up @@ -349,9 +351,12 @@ void evaluateMode() {
int currColor[] = {backgroundColor, numbercolor};
logger("Current color: " + String(backgroundColor), "info");
//logger("Current camNumber: " + String(camNumber), "info");
#if SHOW_CAMERA_NUMBER_DURING_PVW_AND_PGM
// If you want the camera number displayed during Pgm and Pvw, uncomment the following line and comment the line after.
// drawNumber(number[camNumber], currColor);
drawNumber(number[camNumber], currColor);
#else
drawNumber(icons[12], currColor);
#endif
} else {
drawNumber(number[camNumber], offcolor);
}
Expand All @@ -375,6 +380,7 @@ void evaluateMode() {
digitalWrite (led_aux, LOW);
}
#endif

logger("Device is in " + actualType + " (color " + actualColor + " priority " + String(actualPriority) + ")", "info");
// This is a hack to compensate for the Matrix needing GRB.
logger(" r: " + String(g) + " g: " + String(r) + " b: " + String(b), "info");
Expand Down Expand Up @@ -613,6 +619,9 @@ void processTallyData() {
evaluateMode();
}

WiFiManagerParameter* custom_taServer;
WiFiManagerParameter* custom_taPort;

void connectToNetwork() {
// allow for static IP assignment instead of DHCP if stationIP is defined as something other than 0.0.0.0
#if staticIP == 1
Expand All @@ -623,18 +632,17 @@ void connectToNetwork() {
#endif

WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP

logger("Connecting to SSID: " + String(WiFi.SSID()), "info");

//reset settings - wipe credentials for testing
//wm.resetSettings();

//add TA fields
WiFiManagerParameter custom_taServer("taHostIP", "Tally Arbiter Server", tallyarbiter_host, 40);
WiFiManagerParameter custom_taPort("taHostPort", "Port", tallyarbiter_port, 6);
custom_taServer = new WiFiManagerParameter("taHostIP", "Tally Arbiter Server", tallyarbiter_host, 40);
custom_taPort = new WiFiManagerParameter("taHostPort", "Port", tallyarbiter_port, 6);

wm.addParameter(&custom_taServer);
wm.addParameter(&custom_taPort);
wm.addParameter(custom_taServer);
wm.addParameter(custom_taPort);

wm.setSaveParamsCallback(saveParamCallback);

Expand Down Expand Up @@ -738,10 +746,15 @@ void setup() {
//Save battery by turning off BlueTooth
btStop();

uint64_t chipid = ESP.getEfuseMac();
listenerDeviceName = "m5Atom-" + String((uint16_t)(chipid>>32)) + String((uint32_t)chipid);
// Append last three pairs of MAC to listenerDeviceName to make it some what unique
byte mac[6]; // the MAC address of your Wifi shield
WiFi.macAddress(mac);
listenerDeviceName = listenerDeviceName + String(mac[3], HEX) + String(mac[4], HEX) + String(mac[5], HEX);
logger("Listener device name: " + listenerDeviceName, "info");

// Set WiFi hostname
wm.setHostname ((const char *) listenerDeviceName.c_str());

M5.begin(true, false, true);
delay(50);
M5.dis.drawpix(0, 0xf00000);
Expand Down Expand Up @@ -836,25 +849,23 @@ void loop(){
// Switch action below
if (camNumber < 16){
camNumber++;
drawNumber(number[camNumber], offcolor);
} else {
camNumber = 0;
drawNumber(number[camNumber], offcolor);
}

drawNumber(number[camNumber], offcolor);

// Lets get some info sent out the serial connection for debugging
logger("", "info-quiet");
logger("---------------------------------", "info-quiet");
logger("Button Pressed.", "info-quiet");
logger("M5Atom IP Address: " + String(WiFi.localIP()), "info-quiet");
logger("M5Atom IP Address: " + WiFi.localIP().toString(), "info-quiet");
logger("Tally Arbiter Server: " + String(tallyarbiter_host), "info-quiet");
logger("Device ID: " + String(DeviceId), "info-quiet");
logger("Device Name: " + String(DeviceName), "info-quiet");
logger("Cam Number: " + String(camNumber), "info-quiet");
logger("---------------------------------", "info-quiet");
logger("", "info-quiet");
}

// Is WiFi reset triggered?
if (M5.Btn.pressedFor(5000)){
wm.resetSettings();
ESP.restart();
Expand Down
9 changes: 8 additions & 1 deletion listener_clients/m5stickc-listener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Make sure you have selected the **right serial port** and the **right board type

Done! Now your board is running the latest listener client firmware version. Go to the *"Setup your device"* sections to connect the board to the Tally Arbiter server.

NB: The code base is either compiled for m5stickC or m5stickC-Plus based on the define C_PLUS, default is for m5stickC.

# Setup your device
1. Plug the device in a power source
2. Wait for the boot up to finish, if there is no saved AP it will startup an Access Point where you can configure one.
Expand All @@ -47,7 +49,12 @@ Done! Now your board is running the latest listener client firmware version. Go
5. Go back, then go to the "Configure WiFi" page and set your WiFi credentials. The board should reboot.
6. If the connection is successful a settings page will shown. If not, reconnect to 'm5StickC-XXXXXX' Access Point.

If you need to reset WI-FI credentials. Press M5 button for 5 seconds.
Button A (M5):
Single click - Switch between settings screen and device name (the device name is from Tally Arbiter server).
Long press 5 seconds - reset WiFi credentials.

Button B:
Single click - Increase screen brightness

NB: The captive portal page is accessible on the device when the settings screen is shown.

Expand Down
36 changes: 29 additions & 7 deletions listener_clients/m5stickc-listener/m5stickc-listener.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#define RED 0xF800 // 255 0 0
#define maxTextSize 5 //larger sourceName text

String listenerDeviceName = "m5StickC-"; // part of MAC address is added in runtime
// Name of the device - the 3 last bytes of the mac address will be appended to create a unique identifier for the server.
String listenerDeviceName = "m5StickC-";


/* USER CONFIG VARIABLES
Expand All @@ -32,7 +33,7 @@ String listenerDeviceName = "m5StickC-"; // part of MAC address is added in runt
bool LAST_MSG = false; // true = show log on tally screen

//Tally Arbiter Server
char tallyarbiter_host[40] = "192.168.1.173"; //IP address of the Tally Arbiter Server
char tallyarbiter_host[40] = "192.168.0.110"; //IP address of the Tally Arbiter Server
char tallyarbiter_port[6] = "4455";

/* END OF USER CONFIG */
Expand Down Expand Up @@ -69,18 +70,26 @@ String LastMessage = "";
//General Variables
bool networkConnected = false;
int currentScreen = 0; //0 = Tally Screen, 1 = Settings Screen
int currentBrightness = 11; //12 is Max level
int currentBrightness = 11; //12 is Max level on m5stickC but 100 on m5stickC-Plus

WiFiManager wm; // global wm instance
bool portalRunning = false;

// Lcd size
// m5stickC: 80x160
// m5StickC Plus: 135x240

void setup() {
pinMode(TRIGGER_PIN, INPUT_PULLUP);
Serial.begin(115200);
while (!Serial);

// Initialize the M5StickC object
#if C_PLUS == 1
logger("Initializing M5StickCPlus.", "info-quiet");
#else
logger("Initializing M5StickC.", "info-quiet");
#endif

setCpuFrequencyMhz(80); //Save battery by turning down the CPU clock
btStop(); //Save battery by turning off BlueTooth
Expand Down Expand Up @@ -203,11 +212,9 @@ void loop() {
if (btnM5.isClick()) {
switch (currentScreen) {
case 0:
logger("ShowSettings()", "info");
showSettings();
break;
case 1:
logger("ShowDeviceInfo()", "info");
showDeviceInfo();
break;
}
Expand All @@ -221,6 +228,7 @@ void loop() {

void showSettings() {
currentScreen = 1;
logger("showSettings()", "info-quiet");

wm.startWebPortal();
portalRunning = true;
Expand Down Expand Up @@ -249,27 +257,38 @@ void showSettings() {

void showDeviceInfo() {
currentScreen = 0;
logger("showDeviceInfo()", "info-quiet");

if (portalRunning) {
wm.stopWebPortal();
portalRunning = false;
}

M5.Lcd.setTextColor(GREY, BLACK);
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setCursor(4, 82);
M5.Lcd.setFreeFont(FSS24);
M5.Lcd.setTextColor(GREY, BLACK);
M5.Lcd.println(DeviceName);

//displays the currently assigned device and tally data
evaluateMode();
}

void updateBrightness() {
#if C_PLUS == 1
if (currentBrightness >= 100) {
currentBrightness = 7;
} else {
currentBrightness = currentBrightness + 10;
}
#else
if (currentBrightness >= 12) {
currentBrightness = 7;
} else {
currentBrightness++;
}
logger("Set currentBrightness: " + String(currentBrightness), "info");
#endif
logger("Set currentBrightness: " + String(currentBrightness), "info-quiet");
M5.Axp.ScreenBreath(currentBrightness);
}

Expand All @@ -295,6 +314,7 @@ void connectToNetwork() {
//reset settings - wipe credentials for testing
//wm.resetSettings();

//add TA fields
custom_taServer = new WiFiManagerParameter("taHostIP", "Tally Arbiter Server", tallyarbiter_host, 40);
custom_taPort = new WiFiManagerParameter("taHostPort", "Port", tallyarbiter_port, 6);

Expand Down Expand Up @@ -522,6 +542,7 @@ String strip_quot(String str) {
}

void socket_Reassign(String payload) {
logger("socket_Reassign()", "info-quiet");
String oldDeviceId = payload.substring(0, payload.indexOf(','));
String newDeviceId = payload.substring(oldDeviceId.length() + 1);
newDeviceId = newDeviceId.substring(0, newDeviceId.indexOf(','));
Expand Down Expand Up @@ -636,6 +657,7 @@ void evaluateMode() {
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;

if (actualType != "") {
M5.Lcd.setTextColor(BLACK);
M5.Lcd.fillScreen(M5.Lcd.color565(r, g, b));
Expand Down

0 comments on commit ecf47c9

Please sign in to comment.