Measure and Discourse (2019–2021)

About

MEDIS is developed as an environment that provides tools and methods to investigate audience experiences during live performances.

Project details

Tasks

Conception, method, design, coding, research.

Tools
Fusion360, Arduino, Prusa3D, JavaFX

The MEDIS environment

1 MEDIShost

MEDISanalysis

Marker Interface

				
					// MEDIS
// Type of Hardware: Stick-Interface
// Type of Software: Firmware
// Processor: ESP8266 
// Language: C++
// Andreas Pirchner, 2020-2021 

#include <WiFi.h>

const char thisID[3] = "6";                         // set the ID of this device (0-99)
const char deviceType[9] = "joystick";              // declare MAD device type

const char* ssid     = "MADspot";
const char* password = "123456789";
const char* host = "10.10.1.10";                  // fixed ip of the server
const uint16_t port = 5000;                         // net port of the nodejs server

int btnIn = 32;                                     // set GPIO pins
int joyX = 35;                                      // Joystick is 90 degrees rotated,
int joyY = 34;                                      // so X/Y pins need to be switched

int buttonState = 1;                                // declare variables for data
boolean justPressed = false;
boolean pressedAtLastSend = false;
boolean releasedMeanwhile = true;
int xData = 0;
int yData = 0;

char buttonString[32];
char xDataString[32];
char yDataString[32];

char daten[64];
char handshake[32] = "mac,";
boolean clientAccepted = false;

WiFiClient client;                                  // Use WiFiClient class to create TCP connections

void goToSleep() {
  Serial.print("Taking a nap…");
  esp_sleep_enable_timer_wakeup(1000000 * 10);
  esp_deep_sleep_start();
}

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);                             // connect to WiFi
  WiFi.begin(ssid, password);
  Serial.print("Wait for WiFi... ");
  delay(5000);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    //goToSleep();
  }
  Serial.println("WiFi connected, IP address:");
  Serial.println(WiFi.localIP());

  delay(100);

  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  while (!client.connect(host, port)) {           // connect to host server on defined IP address
    Serial.println("connection failed, wait 1 sec...");
    delay(500);
    //goToSleep();
  }

  strcat(handshake, thisID);
  strcat(handshake, ",");
  strcat(handshake, deviceType);
  client.write(handshake);                        // send handshake message to server (identify with device id)

  pinMode(btnIn, INPUT_PULLUP);                          // Set Button pin as Input
  delay(100);
}

void loop() {

  while (WiFi.status() != WL_CONNECTED) {          // check if we're still connected to the MAD network
    Serial.println("reconnecting to WIFI");
    WiFi.begin(ssid, password);                     // if not -> reconnect
    while (WiFi.status() != WL_CONNECTED) { 
      Serial.print(".");
      delay(3000);                                  // wait 3 seconds for connection
    }                                 
  }

  while (WiFi.status() == WL_CONNECTED && !client.connected()){                    // check if we're still connected to the MAD server
    Serial.println("reconnecting to MAD server");
    clientAccepted = false;
    //client.stop();
    client.connect(host, port);                   // if not -> reconnect to host server 
    delay(3000);
  }

  buttonState = digitalRead(btnIn);                // read current button state from GPIO

  if (justPressed == false && buttonState == 1) {
    releasedMeanwhile = true;
  }

  if (buttonState == 0) {
    if (pressedAtLastSend == false && releasedMeanwhile == true) {
      justPressed = true;
      releasedMeanwhile = false;
    }
  }

  if (client.available() > 0)                     // If a message from host is available
  {
    String serverCommand = client.readStringUntil('\n');
    if(serverCommand.startsWith("accepted,")){
      int val = serverCommand.substring(9,10).toInt();
      if (val == 1){
        clientAccepted = true;
        client.write("handshakeReceived,1");
      } else {
        clientAccepted = false;
      }
    }else if (serverCommand.startsWith("alivePing,")) {
      client.write("alive,1");
    }else if (serverCommand.startsWith("requestData,")) {
      String tcString = serverCommand.substring(12, serverCommand.length()+1);
      char tc[9];                                  // maximum timecode: 100.000.000
      tcString.toCharArray(tc,tcString.length()+1);
      xData = analogRead(joyX);                    // read values of X/Y - GPIO pins
      yData = analogRead(joyY);
      delay(10);                                  // wait for 40ms --> time to read the GPIO pins

      if (justPressed) {
        buttonState = 0;
        pressedAtLastSend = true;
        justPressed = false;
      } else {
        buttonState = 1;
        pressedAtLastSend  = false;
      }

      sprintf(buttonString, "%d", buttonState);
      sprintf(xDataString, "%d", xData);
      sprintf(yDataString, "%d", yData);

      strcat(daten, "measurement,");              // build message to send to host
      // Message syntax:
      char delimiter[2] = ",";
      strcat(daten, thisID);                      // 1: device ID
      strcat(daten, delimiter);
      strcat(daten, tc);                          // 2: timecode
      strcat(daten, delimiter);
      strcat(daten, deviceType);                  // 3: deviceType (joystick)
      strcat(daten, delimiter);
      strcat(daten, buttonString);                // 4: button state
      strcat(daten, delimiter);
      strcat(daten, xDataString);                 // 5: x value
      strcat(daten, delimiter);
      strcat(daten, yDataString);                 // 6: y value
      client.write(daten);                      // send message containing measure data to host
      //Serial.println(WiFi.RSSI());              // check WiFi strength
    }
  }

  if (client.connected() && clientAccepted == false) {
    client.write(handshake);                    // try handshake again
    Serial.println("Trying to handshake");
    delay(3000);
  }

  memset(daten, 0, sizeof(daten));              // clear the string holding the measure data
  delay(10);                                    // wait for 40ms at the end of the loop
}

				
			

Tablet Interface

Tablet Interface