Prof. J. Walter - Informationstechnik, Mikrocomputertechnik, Digitale Medien Quellcode
Hochschule Karlsruhe Logo Infomationstechnik
Cocktailmaschine Leertrinkbetrieb
Sommersemester 2020
Rogg, Fabian
Mezger, Felix

Quellcode

Verwendete Arduino Entwicklungsumgebung 1.8.12

Nachfolgend der Code auf dem ESP-Bestellen:

ESP-Bestellen.ino

/*
* Author: Felix Mezger(57667), Fabian Rogg(57667)
* Date: 27.03.2020
* Purpose: Stores the information of scaling ESP and sends this information to ESP Order
* Keep in mind, that ESP Memory is one of the two masters
*/
#include "ESPnow.h"

/* rofa */
extern bool transfer_data[];
extern bool handshake;
int counter= 0;

/* rofa */

bool flag_ESP_Bestellen= false;

cWifiESPNow myobject;


void setup()
{
Serial.begin(115200);
myobject.Init();
myobject.ScanForSlave();
}

void loop()
{

if( counter <4)
{
myobject.manageSlave();
myobject.requestStock();
counter++;

for( int i= 0; i<8; i++)
{
Serial.println("Werte von Transfer");
Serial.println(transfer_data[i]);
}

if( handshake== true)
{
handshake= false;

delay(1000);

for(int i=0;i<8;i++)
{
Serial.write(transfer_data[i]);
}
delay(1800);
}
}
else
{
counter= 0;
ESP.restart();
}
delay(500);
}


ESPnow.h


#include "Ambient.h"
//includes to use ESP_NOW:
#include "esp_now.h"
#include "WiFi.h"


#define NUMSLAVES 2 //Anzahl der Slaves 3: Füllstand, LED und Bedienpanel
#define CHANNEL 1
#define PRINTSCANRESULTS 0




void OnDataSent(const uint8_t* mac_addr, esp_now_send_status_t status); // callback (automatically) when data is sent from Master to Slave
void OnDataRecv(const uint8_t* mac_addr, const uint8_t* pdata, int data_len); //callback (automatically) when data is received from Füllstands - Slave

class cWifiESPNow
{
public:
cWifiESPNow();
void Init(); // Init ESP Now with fallback
void ScanForSlave(); // Scan for slaves in AP mode
void manageSlave(); // Check if the slave is already paired with the master If not, pair the slave with master
bool requestStock(); //Request Füllstand, by sending 99 to Stock-ESP
bool requestorderpanel(); //Request Bedienpanel, by sending 99 to Stock-ESP
bool sendUserInfo(byte led); //Send Userinformation to LED ESP
bool recFlag = false; // Flag set by OnDataRecv when answer from stock ESP32 has been received --> has to be public

private:
int mSlaveCnt;
esp_now_peer_info_t slaves[NUMSLAVES];
};



ESPnow.cpp

#include "ESPnow.h"


/* Limits */

uint8_t GroesseFlasche= 80; // nur für Testzwecke!
//uint8_t GroesseFlasche= 190;
uint8_t KleineFlasche= 70;

/* All Cocktails */


bool grenadine = false;
bool zitrone = false;
bool wodka = false;
bool orange = false;
bool maracuja = false;
bool malibu = false;
bool ananas = false;
bool banane = false;

/* Array for Transfer */
bool transfer_data[8]= {false};

/* Hand Shake */
bool handshake = false;


uint16_t stock[8]={0};

/* All Cocktails */



//bool recFlag=false;
cWifiESPNow::cWifiESPNow()
{
mSlaveCnt = 0;
}

// Init ESP Now with fallback
void cWifiESPNow::Init()
{
WiFi.mode(WIFI_STA); // die zwei Weg?// erst in ESP_Bestellen setup machen?
WiFi.disconnect();
if (esp_now_init() == ESP_OK) {
//#ifdef SERIAL_DEBUG
Serial.println("ESPNow Init Success");
//#endif
}
else {
//#ifdef SERIAL_DEBUG
Serial.println("ESPNow Init Failed");
//#endif
// Retry InitESPNow, add a counte and then restart?
// InitESPNow();
// or Simply Restart
ESP.restart();
}
//#ifdef SERIAL_DEBUG
Serial.print("Wifi Mixing Unit MAC-Adress: "); Serial.println(WiFi.macAddress());
//#endif
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
};

// Scan for slaves in AP mode
void cWifiESPNow::ScanForSlave() {
int8_t scanResults = WiFi.scanNetworks();
//reset slaves
memset(slaves, 0, sizeof(slaves));
mSlaveCnt = 0;
Serial.println("");
if (scanResults == 0) {
//#ifdef SERIAL_DEBUG
Serial.println("No WiFi devices in AP Mode found");
//#endif
}
else {
//#ifdef SERIAL_DEBUG
Serial.print("Found "); Serial.print(scanResults); Serial.println(" devices ");
//#endif
for (int i = 0; i < scanResults; ++i) {
// Print SSID and RSSI for each device found
String SSID = WiFi.SSID(i);
int32_t RSSI = WiFi.RSSI(i);
String BSSIDstr = WiFi.BSSIDstr(i);

if (PRINTSCANRESULTS) {
Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println("");
}
delay(10);
// Check if the current device starts with `Slave`
if (SSID.indexOf("CmIoTSlave") == 0) {
// SSID of interest
Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println("");
// Get BSSID => Mac Address of the Slave
int mac[6];

if (6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5])) {
for (int ii = 0; ii < 6; ++ii) {
slaves[mSlaveCnt].peer_addr[ii] = (uint8_t)mac[ii];
}
}
slaves[mSlaveCnt].channel = CHANNEL; // pick a channel
slaves[mSlaveCnt].encrypt = 0; // no encryption
mSlaveCnt++;
}
}
}
if (mSlaveCnt > 0) {
//#ifdef SERIAL_DEBUG
Serial.print(mSlaveCnt); Serial.println(" Slave(s) found, processing..");
//#endif
}
else {
//#ifdef SERIAL_DEBUG
Serial.println("No Slave Found with Prefix CmIoTSlave");
//#endif
}

// clean up ram
WiFi.scanDelete();
}

// Check if the slave is already paired with the master.
// If not, pair the slave with master
void cWifiESPNow::manageSlave() {
if (mSlaveCnt > 0) {
for (int i = 0; i < mSlaveCnt; i++) {
const esp_now_peer_info_t* peer = &slaves[i];
const uint8_t* peer_addr = slaves[i].peer_addr;
//#ifdef SERIAL_DEBUG
Serial.print("Processing: ");
for (int ii = 0; ii < 6; ++ii) {
Serial.print((uint8_t)slaves[i].peer_addr[ii], HEX);
if (ii != 5) Serial.print(":");
}
//#endif
//Debug informations: Status
//#ifdef SERIAL_DEBUG
Serial.print(" Status: ");
//#endif
// check if the peer exists
bool exists = esp_now_is_peer_exist(peer_addr);
if (exists) {
// Slave already paired.
//#ifdef SERIAL_DEBUG
Serial.println("Already Paired");
//#endif
}
else {
// Slave not paired, attempt pair
esp_err_t addStatus = esp_now_add_peer(peer); //Pairing of Devices
//#ifdef SERIAL_DEBUG
if (addStatus == ESP_OK) {
// Pair success
Serial.println("Pair success"); //Serial print of failures:
}
else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT) {
// How did we get so far!!
Serial.println("ESPNOW Not Init");
}
else if (addStatus == ESP_ERR_ESPNOW_ARG) {
Serial.println("Add Peer - Invalid Argument");
}
else if (addStatus == ESP_ERR_ESPNOW_FULL) {
Serial.println("Peer list full");
}
else if (addStatus == ESP_ERR_ESPNOW_NO_MEM) {
Serial.println("Out of memory");
}
else if (addStatus == ESP_ERR_ESPNOW_EXIST) {
Serial.println("Peer Exists");
}
else {
Serial.println("Not sure what happened");
}
//#endif
delay(100);
}
}
}
else {
// No slave found to process
//#ifdef SERIAL_DEBUG
Serial.println("No Slave found to process");
//#endif
}
}


// send data to LED device
bool cWifiESPNow::sendUserInfo(byte led) {

ScanForSlave();
if (mSlaveCnt > 0) { // check if slave channel is defined
manageSlave();

for (int i = 0; i < mSlaveCnt; i++) { //Send data to ALL Slaves
const uint8_t* peer_addr = slaves[i].peer_addr; //necessary cast
if (i == 0) { // print only for first slave
//#ifdef SERIAL_DEBUG
Serial.print("Sending: ");
Serial.println(led);
//#endif
}
esp_err_t result = esp_now_send(peer_addr, &led, sizeof(led)); //send data

//Debug informations Send Status:
//#ifdef SERIAL_DEBUG
Serial.print("Send Status: ");
//#endif
if (result == ESP_OK)
{
//#ifdef SERIAL_DEBUG
Serial.println("Success");
//#endif
return (true);
}
//#ifdef SERIAL_DEBUG
else if (result == ESP_ERR_ESPNOW_NOT_INIT)
Serial.println("ESPNOW not Init.");
else if (result == ESP_ERR_ESPNOW_ARG)
Serial.println("Invalid Argument");
else if (result == ESP_ERR_ESPNOW_INTERNAL)
Serial.println("Internal Error");
else if (result == ESP_ERR_ESPNOW_NO_MEM)
Serial.println("ESP_ERR_ESPNOW_NO_MEM");
else if (result == ESP_ERR_ESPNOW_NOT_FOUND)
Serial.println("Peer not found.");
else
Serial.println("Not sure what happened");
//#endif
return(false);
}
}
else
{
//#ifdef SERIAL_DEBUG
Serial.println("No Slave found");
//#endif
return (false);
}
}

//Füllstand anfragen
bool cWifiESPNow::requestStock()
{

uint16_t count = 0; // used to count time from request to received data
// BESSER MIT millis() INTEGRIEREN???
//ScanForSlave(); // search for all devices in AP mode with Prefix "CmIoTSlave"


if (mSlaveCnt > 0) //&&(request==88)) // activating request in html whatever

{ // if slave had been found during last scan...
//manageSlave();

byte request = 88; // set by button click/action

for (int i = 0; i < mSlaveCnt; i++)
{
const uint8_t* peer_addr = slaves[i].peer_addr; //necessary cast
//#ifdef SERIAL_DEBUG

if (i == 0)
{
// print only for first slave
Serial.print("Sending: ");
Serial.println(request);
}

// #endif

esp_err_t result = esp_now_send(peer_addr, &request, sizeof(request)); //send data

//Debug informations Send Status:
// #ifdef SERIAL_DEBUG
Serial.print("Send Status: ");
// #endif

if (result == ESP_OK)
{
// #ifdef SERIAL_DEBUG
Serial.println("Success");
//#endif

while (!recFlag) // wait until receiveFlag has been set by receive interrupt routine
{ // hier Timeout integrieren

if (count < 1000)
{
count++;
}

else
{
//#ifdef SERIAL_DEBUG
Serial.println("Timeout while waiting for answer from stock esp32");
//#endif
return false; // return error
}
delay(1);
}// while-Schleife


//#ifdef SERIAL_DEBUG
for (int i = 0; i < 8; i++)
{
Serial.printf("Received Stock %d: %d\n", i, stock[i]);
}

Serial.printf("Time Waited for Answer %d ms\n", count);
// #endif

recFlag = false; // reset recFlag
return (true);




}// if(result==ESP_ok)



// #ifdef SERIAL_DEBUG
else if (result == ESP_ERR_ESPNOW_NOT_INIT)
Serial.println("ESPNOW not Init.");
else if (result == ESP_ERR_ESPNOW_ARG)
Serial.println("Invalid Argument");
else if (result == ESP_ERR_ESPNOW_INTERNAL)
Serial.println("Internal Error");
else if (result == ESP_ERR_ESPNOW_NO_MEM)
Serial.println("ESP_ERR_ESPNOW_NO_MEM");
else if (result == ESP_ERR_ESPNOW_NOT_FOUND)
Serial.println("Peer not found.");
else
Serial.println("Not sure what happened");
// #endif
delay(100);
return (false);

}// Ende for-Schleife
}




else // if no slaves have been found during last scan...
{
//#ifdef SERIAL_DEBUG
Serial.println("No Slave found to request stock");
// #endif
return (false);
}
}






// callback (automatically) when data is sent from Master to Slave
void OnDataSent(const uint8_t* mac_addr, esp_now_send_status_t status)
{
char macStr[18];
//#ifdef SERIAL_DEBUG
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
Serial.print("Last Packet Sent to: "); Serial.println(macStr);
Serial.print("Last Packet Send Status: "); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
//#endif
}

//callback (automatically) when data is received from Füllstands - Slave
void OnDataRecv(const uint8_t* mac_addr, const uint8_t* pdata, int data_len)
{
uint16_t stock[8]={0};
cWifiESPNow wifiCom; // object of this class included to have access to recFlag
uint8_t* receivedData = (uint8_t*)stock; // Local Pointer on Stock Array (Füllstand)

char macStr[18];
// Serial print Mac-Adress of Slave
//#ifdef SERIAL_DEBUG
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
//#endif

for (int i = 0; i < 16; i++) // ursprünglich 16, warum nicht 8(versuch es mal)
{
receivedData[i] = pdata[i]; //Copy received Data into receivedData-Array (= Stock-Array)
}

wifiCom.recFlag = true; // set receive Flag, to allow following actions in requestStock()-Method


/* Part of Calculation, which ingredients are enough in terms of their limit */

if(stock[0] >= KleineFlasche)
{

grenadine= true;
transfer_data[0]= grenadine;
// Serial.println(grenadine);
}
else
{
grenadine=false;
transfer_data[0]= grenadine;
// Serial.println(grenadine);
}

if(stock[1] >= KleineFlasche)
{
zitrone= true;
transfer_data[1]=zitrone ;
// Serial.println(zitrone);
}

else
{

zitrone= false;
transfer_data[1]=zitrone ;
// Serial.println(zitrone);
}


if(stock[2] >= GroesseFlasche)
{
wodka= true;
transfer_data[2]=wodka ;
// Serial.println(wodka);
}

else
{
wodka= false;
transfer_data[2]=wodka ;
// Serial.println(zitrone);
}
if(stock[3] >= KleineFlasche)
{

orange= true;
transfer_data[3]=orange ;
Serial.println(orange);
}
else
{
orange=false;
transfer_data[3]=orange ;
// Serial.println(orange);
}

if(stock[4] >= KleineFlasche)
{
maracuja= true;
transfer_data[4]=maracuja;
// Serial.println(maracuja);
}

else
{
maracuja= false;
transfer_data[4]=maracuja ;
// Serial.println(maracuja);
}
if(stock[5] >= GroesseFlasche)
{

malibu= true;
transfer_data[5]= malibu;
// Serial.println(malibu);
}
else
{
malibu=false;
transfer_data[5]= malibu;
// Serial.println(malibu);
}

if(stock[6] >= KleineFlasche)
{
ananas= true;
transfer_data[6]= ananas;
// Serial.println(ananas);
}

else
{
ananas= false;
transfer_data[6]= ananas;
// Serial.println(ananas);
}
if(stock[7] >= KleineFlasche)
{
banane= true;
transfer_data[7]= banane;
// Serial.println(banane);
}

else
{
banane= false;
transfer_data[7]= banane;
// Serial.println(banane);
}





/*
for(int i=0; i<8; i++)
{
Serial.println("Ausgabe der Werte: ");
Serial.println(stock[i]);


}
*/








//For Debugging:
//#ifdef SERIAL_DEBUG
Serial.print("Last Packet Recv from: "); Serial.println(macStr);
Serial.println("Last Packet Recv Data copied into Stock-Variable: ");
//#endif
/* rofa */
handshake = true;
/* rofa */
}



Nun folgt die ESP-Bestellen, hier wird aber nur der selbstgeschriebene, projektbezogene Code eingefügt, da der Rest einfach viel zu viel wäre.

ESP-Bestellen.ino

/* rofa */
cWifiESPNow ESPnow_object;
bool incomingByte[8]={false};
bool receive_data=false;
int counter= 0;
void permissionstart1();
void permissionstart2(char param);
bool getstarted= false;
char counter2=0;


/* All Ingredients */
bool grenadine = false;
bool zitrone = false;
bool wodka = false;
bool orange = false;
bool maracuja = false;
bool malibu = false;
bool ananas = false;
bool banane = false;

bool auswertungs_array[8]={false, false, false, false, false, false, false, false};


bool *pointer_to_auswertungs_array;

void justtrying();

extern bool alcoholic_cocktails[];
extern bool non_alcoholic_cocktails[];

bool flag_for_building_jquery= false;
bool flag_for_building_cocktails= false;
/* rofa */

 empty_drink_mode_html.append(LEERTRINKBETRIEB_page_Begin);
empty_drink_mode_html.append(LEERTRINKBETRIEB_page_middle);
empty_drink_mode_html.append(LEERTRINKBETRIEB_page_After);
empty_drink_mode_html.append(JAVASCRIPT_static);
empty_drink_mode_html.append(LEERTRINKBETRIEB_page_AfterScript);
server.on("/empty_drink_mode", HTTP_GET, [](AsyncWebServerRequest* request){
AsyncWebServerResponse * response= request->beginResponse(200);
request-> send_P(200,"text/html",empty_drink_mode_html.c_str(), processor);
});


void loop()
{

/* Beginn der UART Kommunikation */
/* 1. Erhalt der UART Nachricht
* 2. Filtern der Nachrichten/ es kommen manchmal unsynchronisierte/ falsche Daten, die werden herraus gefiltert!
3. Auslesen der Nachricht -> 8 Werte werden geschcikt(0 oder 1), die stehen für die einzelnen Getränkzutaten 1= es ist genügend da, 0= es ist zu wenig
4. UART Array wird dem Auswertungsarray übergeben
5. Informationen werden aus dem Auswertungsarray herrausgenommen und in einzelne Variablen gespeichtert( Grenadine, Wodka , Malibu etc.)
6. Aufruf der Funktionen, um herauszufinden, ob einzelne Cocktails machbar sind oder nicht siehe functions.cpp, dies wird dann in ein alc-array/ non-alc-array gespeichtert

So viel zu dem Loop

Leertrinkbetrieb.h

statische Teil des empty-drink_mode

Leertrinkbetrieb.cpp

dynamische Teil, hier werden die zwei Arrays (alc-array und non-alc array mit einer if-Bedinung ausgelesen, um nur die möglichen Cocktails darzustellen

*/
if(Serial.available())
{
/* Handshake, der nicht so gut funktionierte */ /*
if( Serial.read()== true)
{
getstarted= true;
Serial.write(getstarted);
delay(10);
*/
for(int i=0; i<8; i++)
{
//counter++;
incomingByte[i]= Serial.read();
//Serial.print(incomingByte[i]);

}

/* Handshake
if (counter== 8)
{
getstarted= false;
}
*/

/* Filter */
for(int b=0; b<8; b++)
{

if(incomingByte[b] == true)
{
counter2= counter2+1;
}
else if(incomingByte[b] == false)
{
//break;
}
}

if(counter2 == 8)
{
//Serial.print(0);
}
else if(counter2 <8)
{
for(int c=0; c<8; c++)
{
auswertungs_array[c]=incomingByte[c];
//Serial.println(auswertungs_array[c]);
}
}
counter2=0;


/* Start der Zuweisung */


pointer_to_auswertungs_array= auswertungs_array;
if (*(pointer_to_auswertungs_array) == true)
{
grenadine = true;
}
else
{
grenadine = false;
}
//Serial.println("Wert Grenadine:");
Serial.println(grenadine);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
zitrone = true;
}
else
{

zitrone = false;
}
//Serial.println("Wert Zitrone:");
Serial.println(zitrone);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
wodka = true;
}
else
{

wodka = false;
}
//Serial.println("Wert Wodka:");
Serial.println(wodka);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
orange = true;
}
else
{

orange = false;
}
//Serial.println("Wert Orange:");
Serial.println(orange);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
maracuja = true;
}
else
{

maracuja = false;
}
//Serial.println("Wert Maracuja:");
Serial.println(maracuja);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
malibu = true;
}
else
{

malibu = false;
}
//Serial.println("Wert Malibu:");
Serial.println(malibu);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
ananas = true;
}
else
{

ananas = false;
}
//Serial.println("Wert Ananas:");
Serial.println(ananas);

pointer_to_auswertungs_array++;

if (*(pointer_to_auswertungs_array) == true)
{
banane = true;
}
else
{

banane = false;
}
//Serial.println("Wert Banane:");
Serial.println(banane);
Serial.println();
Serial.println();
Serial.println("Next Message");


/* Check all alcoholic cocktails*/

// Alkoholische Getränke
wodka_maracuja_1(wodka, maracuja);
malibu_maracuja_2(malibu, maracuja);
malibu_orange_3(malibu, orange);
malibu_orange_grenadine_4(malibu, orange, grenadine);
wodka_orange_5(wodka, orange);
wodka_malibu_orange_6(wodka,malibu, orange);
wodka_malibu_ananas_7(wodka, malibu, ananas);
wodka_grenadine_ananas_8(wodka, grenadine, ananas);
wodka_zitrone_9(wodka, zitrone);
wodka_zitrone_maracuja_ananas_grenadine_banane_orange_10(wodka, zitrone, maracuja, ananas, grenadine, banane, orange);
wodka_ananas_11(wodka, ananas);
wodka_orange_12(wodka, orange);

delay(1000);

/*
Serial.println("Alkoholische Liste an Cocktails:");
for(int i=0; i<12;i++)
{

Serial.print(alcoholic_cocktails[i]);
}
Serial.println();
*/

// Antialkoholische Getränke

maracuja_1(maracuja);
orange_2(orange);
maracuja_orange_ananas_zitrone_grenadine_3(maracuja, orange, ananas, zitrone, grenadine);
banane_ananas_maracuja_grenadine_4(banane, ananas, maracuja, grenadine);
zitrone_orange_5(zitrone, orange);
grenadine_zitrone_orange_maracuja_ananas_6(grenadine, zitrone, orange, maracuja, ananas);
zitrone_grenadine_orangensaft_ananas_7(zitrone, grenadine, orange, ananas);
zitrone_grenadine_orange_maracuja_ananas_8(zitrone, grenadine, orange, maracuja, ananas);
zitrone_grenadine_maracuja_orange_ananas_9(zitrone, grenadine, orange, maracuja, ananas);
grenadine_zitrone_orange_banane_10(grenadine, zitrone, orange, banane);
zitrone_grenadine_maracuja_ananas_11(zitrone, grenadine, maracuja, ananas);
zitrone_grenadine_orange_maracuja_12(zitrone, grenadine, orange, maracuja);
ananas_orange_13(ananas, orange);
zitrone_orange_ananas_14(zitrone, orange, ananas);
zitrone_orange_ananas_15(zitrone, orange, ananas);
grenadine_orange_ananas_16(grenadine, orange, ananas);
orange_maracuja_ananas_17(orange, maracuja,ananas);
grenadine_orange_ananas_18(grenadine, orange, ananas);




/* rofa */
Serial.println("Anti-Alkoholische Liste an Cocktails:");
for(int i=0; i<18;i++)
{

Serial.print(non_alcoholic_cocktails[i]);
}


DynamicJsonDocument cocktails(2048);

File filec = SPIFFS.open("/cocktails.json", FILE_WRITE);
if (!filec) {
Serial.println("There was an error opening the file /cocktails.json for writing");
}
else
{ JsonArray alccock=cocktails.createNestedArray("alccock");
JsonArray nonalccock=cocktails.createNestedArray("nonalccock");
for(int i=0; i<12; i++)
{

alccock.add(alcoholic_cocktails[i]);

}
for (int i=0; i<18; i++)
{
nonalccock.add(non_alcoholic_cocktails[i]);
}
if (serializeJson(cocktails, filec) == 0) {
Serial.println(F("Failed to write to file"));
}
else
{
Serial.println(F("File /cocktail.json written"));
serializeJson(cocktails,Serial);
}
filec.close();
server.on("/js/cocktails.json", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send(SPIFFS, "/cocktails.json", "text/json");
});
}






//}
}

else
{
delay(500);
}



//}


/* rofa */
}

Leertrinkbetrieb.h

#include <Arduino.h>
#include <string>
using namespace std;

string dynamic_content_leertrinkbetrieb_alc();
string dynamic_content_leertrinkbetrieb_nonalc();

const char LEERTRINKBETRIEB_page_Begin[] PROGMEM{ R"=====(

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="Cocktail orderingpage" content="This site provides all purchaseable cocktails">
<meta name="cocktail" content="example, html, head, meta">

<link rel="shortcut icon" href="image/favico.ico" type="image/x-icon">
<link rel="icon" href="image/favico.ico" type="image/x-icon">
<title>MixHit Order</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">

<!-- Custom styles for this template -->
<link rel="stylesheet" href="css/design.css">

<script src="js/jquery3.5.0.min.js" type="text/javascript" ></script>

</head>

<body id="page-top">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="mainNav">
<div class="container">
<img class="logo_image" src="image/hska_logo.png">
<a class="navbar-brand" href="#page-top">Hochschule Karlsruhe - MixHit</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
aria-controls="navbarResponsive"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a
class="nav-link js-scroll-trigger"
href="#services"
>empty_drink_mode</a
>
</li>
</ul>
</div>
</div>
</nav>

<header class="text-white">
<div class="container text-center">
<h1>You are now in the empty drink mode </h1>
<p class="lead">
Enjoy it!
</p>
</div>
</header>
<section id="leertrinkbetrieb" class="bg-light">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<h3>You will see all cocktails, which are available with the current ingredients</h3>

<section id="Alc">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2>Alcoholic Cocktails</h2>
<p class="lead">Choose your drink!!!</p>

<table class="table">
<thead>
<tr>
<th style="text-align:center;">#</th>
<th style="text-align:center;">Cocktail</th>
<th style="text-align:center;">Ingriedients</th>
<th style="text-align:center;">Size</th>
</tr>
</thead>
<tbody id="Alc2">
</tbody>
<script>
var alc_cocktails=[];
var alc_Cocktail=["Wodka-Maracuja","Malibu-Maracuja","Malibu-Orange","Malibu-Sunrise","Screwdriver","Tropic-Thunder","Mix-Mimi","Pink-Pussycat","Mix-Safari","San-Francisco","The-Waikiki","Mix-Brassmonkey"];
var alk_Zutaten=["Wodka, Maracuja","Malibu, Maracuja","Malibu, Orange","Malibu, Grenadine, Orange","Wodka, Orange",
"Wodka, Malibu, Maracuja","Wodka, Malibu, Ananas","Wodka, Grenadine, Ananas","Wodka, Zitrone",
"Wodka, Maracuja, Ananas, Zitrone, Grenadine, Orange, Banane","Wodka, Ananas","Wodka, Orange(anderes Verhältnis)"];
var Zaehler_alc=0;


setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {

$.getJSON("/js/cocktails.json", function(json){
console.log(json.alccock);
alc_cocktails=json.alccock;
});


document.getElementById("Alc2").innerHTML = "";
Zaehler_alc=0;
for (var counter=0;counter <12; counter++)
{ var lIngredients = "";
lIngredients+= alk_Zutaten[counter];

if ( alc_cocktails[counter]==true)
{Zaehler_alc++;

document.getElementById("Alc2").innerHTML += "<tr>\n";
document.getElementById("Alc2").innerHTML +="<td scope=\"row\" style=\"text-align:center;\" >" + String(Zaehler_alc) + "</td>\n"
+ "<td style=\"text-align:center;\"><strong> " + String(alc_Cocktail[counter]) + "</strong></td>\n"
+"<td><em>" + lIngredients + "</em></td>\n"
+ "<td style=\"text-align:center;\"><button id =\""+String(alc_Cocktail[counter])+ "\"class=\"btn btn-danger btn-block\" data-modal-target=#modalalc> " + String(220) + "ml</button></td>\n";
document.getElementById("Alc2").innerHTML +="</tr>\n";
}}


};

xhttp.open("GET", "/empty_trink_mode", true);
xhttp.send();
}, 10000 ) ;
</script>

)=====" };

const char LEERTRINKBETRIEB_page_middle[] PROGMEM{ R"=====(

</table>
</div>
</div>
</div>
</section>
<section id="Alc">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2>Non-alcoholic Cocktails</h2>
<p class="lead">Choose your drink!!!</p>

<table class="table">
<thead>
<tr>
<th style="text-align:center;">#</th>
<th style="text-align:center;">Cocktail</th>
<th style="text-align:center;">Ingriedients</th>
<th style="text-align:center;">Size</th>
</thead>
<tbody id="Non_Alc2">
</tbody>
<script>
var non_alc_cocktails=[];
var non_Cocktail=["Maracuja","Orange","Taifruitpunch","Tropic-Sunrise","Lemon-Cocktail","Mix-Sixteen","Mix-Redone","Mix-Planterswonder","Mix-Targa","Bananajack","Bora-Bora","Drachenblut","Mix-Kiba","Luckydriver","Ananas-Orange","Babouin","Ballerina","Cinderella","Mix-Sweetvictory","Mix-Sweety","Tropic-Star","Tropical-Orange" ];
var non_alc_Zutaten=["Maracuja","Orange","Maracuja, Orange, Ananas, Zitrone, Grenadine","Banane, Ananas, Maracuja, Grenadine",
"Zitrone, Orange", "Grenadine, Zitrone, Orangen, Maracuja, Ananas","Zitrone, Grenadine, Orangensaft, Ananas","Zitrone, Grenadine, Orange, Maracuja, Ananas",
"Zitrone, Grenadine, Maracuja, Orange, Ananas(anderes Verhältnis)","Grenadine, Zitrone, Orange, Banane"," Zitrone, Grenadine, Maracuja, Ananas",
"Zitrone, Grenadine, Orange, Maracuja", "Ananas, Orange", "Zitrone, Orange, Ananas", "Zitrone, Orange, Ananas(anderes Verhältnis)","Grenadine, Orange, Ananas",
"Orange, Maracuja, Ananas", "Grenadine, Orange, Ananas"];





setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {

$.getJSON("/js/cocktails.json", function(json){
console.log(json.nonalccock);
non_alc_cocktails=json.nonalccock;

});



document.getElementById("Non_Alc2").innerHTML = "";
Zaehler_alc=0;
for (var counter=0;counter <18; counter++)
{
var lIngredients2 = "";
lIngredients2+= non_alc_Zutaten[counter];

if (non_alc_cocktails[counter]==true)
{Zaehler_alc++;

document.getElementById("Non_Alc2").innerHTML += "<tr>\n";
document.getElementById("Non_Alc2").innerHTML +="<td scope=\"row\" style=\"text-align:center;\" >" + String(Zaehler_alc) + "</td>\n"
+ "<td style=\"text-align:center;\"><strong> " + String(non_Cocktail[counter]) + "</strong></td>\n"
+"<td><em>" + lIngredients2 + "</em></td>\n"
+ "<td style=\"text-align:center;\"><button id =\""+String(non_Cocktail[counter])+ "\"class=\"btn btn-danger btn-block\" data-modal-target=#modalalc> " + String(220) + "ml</button></td>\n";



document.getElementById("Non_Alc2").innerHTML +="</tr>\n";
}}
};

xhttp.open("GET", "/empty_trink_mode", true);
xhttp.send();
}, 10000 ) ;
</script>


)=====" };

const char LEERTRINKBETRIEB_page_After[] PROGMEM{ R"=====(

</table>
</div>
</div>
</div>
</section>
<div class="modalalc" id="modalalc">
<div class="modalalc-header h4">
<div class="title">Ihre Bestellung</div>
<button data-close-button class="close-button">&times;</button>
</div>
<div class="modalalc-body h5">
<strong>Ihre Bestellung wird gebucht.</strong><br />
<em>Stellen Sie das Glas auf das Terminal.</em>
</div>
</div>

<div class="modalnonalc" id="modalnonalc">
<div class="modalnonalc-header h4">
<div class="title">Ihre Bestellung</div>
<button data-close-button class="close-button">&times;</button>
</div>
<div class="modalnonalc-body h5">
<strong>Ihre Bestellung wird gebucht.</strong><br />
<em>Stellen Sie das Glas auf das Terminal.</em>
</div>
</div>

<div class="total1" id="total1">
<div class="total-header1 h4">
<div class="title">Kasse</div>
<button total-close-button class="close-button">&times;</button>
</div>
<div class="total-body1 h5">
<strong>Ihre Bestellung wird berechnet.</strong><br />
<p class="h4">
Zu zahlender Betrag:
<strong><em onload="calculatePrice()" id="cost"></em>
<em>&euro;</em></strong>
</p>
<div class="form-group mx-sm-3 mb-2">
<input
class="form-control float-left"
type="number"
name="paid"
id="paid" data-decimals="2" min="0" max="999.99" step="0.1"
placeholder="0.0"
onkeypress="return isNumberKey(event)" onkeydown="isEnterKey(event)"
/><button class="btn btn-info float-right btn-calc"
onclick="calculateReturn()">
Calculate
</button>
</div>
<div class="h4"> <p id="return"></p></div>
</div>
</div>
<div id="overlay"></div>
<!-- Footer -->
<footer class="py-2">
<div class="container">
<div id="left">Copyright &copy; Your Website 2020</div>
<div id="center">
Price:
<strong><em id="display"></em><em>&euro;</em></strong>
</div>
<div id="right">
<button class="btn btn-success" data-modal-target="#total1">
Total
</button>
</div>
</div>
<!-- /.container -->
</footer>
<script>
)=====" };

const char LEERTRINKBETRIEB_page_AfterScript[] PROGMEM{ R"=====(
</script>
</body>
</html>
)=====" };



ESP-Wiegen


#include "esp_now.h"
#include "WiFi.h"
#include <EEPROM.h>
#include <Wire.h>
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h"

#define MUX_Address 0x70 // TCA9548A Encoders address

NAU7802 myScale[8]; //Create instance of the NAU7802 class

int NUMBER_OF_SENSORS = 8; // Anzahl der Sensoren, welche an der MUX angeschlossen sind
float currentweight[] = {0, 0, 0, 0, 0, 0, 0, 0}; // aktuelles gewicht, wird mit jedem lese zyklus geschrieben
unsigned long StartTime = 0; // ANALYSE
float calibfactor[8] = {213.24, 211.37, 214.65, 216.64, 215.91, 215.00, 218.10, 214.59}; // calibration factor mit 100g prüfgewicht
float offsetfactor[8] = { -32782, -35528, 67204, 205027 , -84069, 139070, 124106, -105701}; // offset factor von leerer Waage ohne flasche nur mit halter
float Null_ml_Gewichte[8] = {948, 948, 948, 1482, 1482, 948, 948, 948}; // leere Flasche im Halter mit füllstand anfang Zylinder (0ml marke)
float Fuellgewicht[8]; // falls ml ausgegeben werden soll und nicht mehr gramm
float Fuellhoehe[8]; // falls füllhöhe ausgegeben werden soll und nicht mehr gramm
float Fuellgewicht_voll[]={1316,1316,1316,2018,2018,1316,1316,1316};

float offset = 0;
float y = 0;
long e=0;
// Variablen und includes für LED Ausgabe
#include <Adafruit_NeoPixel.h>
float LED_Farbe_0_255[8]; // float zur berechnung
int LED_Farbe_0_255_int[8];// int zur ausgabe
float i = 255;
float dreiL_Voll = 2018; // volldefinition 3L Flasche
float einskommafunefiL_Voll = 1316; // volldefinition 1,5L Flasche
float dreiL_faktor; // faktor für led skalierung in 255stel
float einskommafuenfL_faktor; // faktor für led skalierung in 255stel
int32_t tarereading[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // für tare nach neuem strom bei boot mit tareschalter

#define Tare 25 // Tare Pin
#define PIN 16 //LED Ausgangs-Pin
#define NUMPIXELS 90 //Anzahl der NeoPixel

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //LED


// tare funktion um abweihungen vom null punkt auszugleichen wird ausgeführt wenn bei reset knopf gedrückt wird
void taregewicht()
{
for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
{
tcaselect(x);
tarereading[x] = myScale[x].getWeight();
}
}


void tcaselect(uint8_t i2c_bus)// mux weiter schalten um zwischen den 8 waagen zu wechseln
{
if (i2c_bus > 7) return;
Wire.beginTransmission(MUX_Address);
Wire.write(1 << i2c_bus);
Wire.endTransmission();
}

// esp now übertragung
//--------------------------------------------------------------------------------------------------------------


//Local master
esp_now_peer_info_t master = {};
esp_now_peer_info_t master2 = {};

//MAC Adress of Master (in master code: WiFi.macAddress())
uint8_t master_mac[6] = { 0xCC, 0x50, 0xE3, 0xB6, 0x2D, 0xD0 };
uint8_t master_mac2[6] = { 0xA4, 0xCF, 0x12,0x9A, 0x00, 0x78}; //Master 2

#define CHANNEL 1

// Init ESP Now with fallback
void InitESPNow() {
WiFi.disconnect();
if (esp_now_init() == ESP_OK) {
Serial.println("ESPNow Init Success");
}
else {
Serial.println("ESPNow Init Failed");
// Retry InitESPNow, add a counte and then restart?
// InitESPNow();
// or Simply Restart
ESP.restart();
}
}


//Slave configured as Access Point (AP) SSID
void configDeviceAP() {
String Prefix = "CmIoTSlave:";
String Mac = WiFi.macAddress();
String SSID = Prefix + Mac;
String Password = "123456789";
bool result = WiFi.softAP(SSID.c_str(), Password.c_str(), CHANNEL, 0);
if (!result) {
Serial.println("AP Config failed.");
}
else {
Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
}
}


//Data to send: Füllstandsarray zur Übertragung ( stock[8] wird gesendet)
uint16_t stock[8] = { 200, 900, 500, 900, 500, 900, 500, 500 }; //Stock
uint8_t* sendData = (uint8_t*)stock; //Array to send data. Must be byte (uint8_t)
bool requestData = false; //Request Flag (received from mixing unit) ->send data.

uint16_t stock2[8] = { 200, 900, 500, 900, 500, 900, 500, 500 }; //Stock
uint8_t* sendData2 = (uint8_t*)stock2; //Array to send data. Must be byte (uint8_t)
bool requestData2 = false; //Request Flag (received from mixing unit) ->send data.



// send filling data to master:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SEND
void sendStock() {

//castToSend(stock, sendData); //Necessary cast to convert uint 16 to uint 8 for sending

const uint8_t* peer_addr = master.peer_addr; //Adjusted. cast to const neccessary!!!
Serial.print("Sending: ");
for (int i = 0; i < 8; i++)
{
Serial.print(stock[i]);
Serial.println(" ");
}
esp_err_t result = esp_now_send(peer_addr, sendData, sizeof(stock)); //Send funktion

//Debug information Send Status:
Serial.print("Send Status: ");
if (result == ESP_OK) {
Serial.println("Success");
requestData = false; // Delete request Data flag. //Alternativ in Callback-Fkt??
}
else if (result == ESP_ERR_ESPNOW_NOT_INIT)
Serial.println("ESPNOW not Init.");
else if (result == ESP_ERR_ESPNOW_ARG)
Serial.println("Invalid Argument");
else if (result == ESP_ERR_ESPNOW_INTERNAL)
Serial.println("Internal Error");
else if (result == ESP_ERR_ESPNOW_NO_MEM)
Serial.println("ESP_ERR_ESPNOW_NO_MEM");
else if (result == ESP_ERR_ESPNOW_NOT_FOUND)
Serial.println("Peer not found.");
else
Serial.println("Not sure what happened");

}

void sendStock2() {

//castToSend(stock, sendData); //Necessary cast to convert uint 16 to uint 8 for sending

const uint8_t* peer_addr2 = master2.peer_addr; //Adjusted. cast to const neccessary!!!
Serial.print("Sending: ");
for (int i = 0; i < 8; i++)
{
Serial.print("Ausgabe Stock2");
Serial.print(stock2[i]);
Serial.println(" ");
}
esp_err_t result = esp_now_send(peer_addr2, sendData2, sizeof(stock2)); //Send funktion

//Debug information Send Status:
Serial.print("Send Status: ");
if (result == ESP_OK) {
Serial.println("Success");
requestData2 = false; // Delete request Data flag. //Alternativ in Callback-Fkt??
}
else if (result == ESP_ERR_ESPNOW_NOT_INIT)
Serial.println("ESPNOW not Init.");
else if (result == ESP_ERR_ESPNOW_ARG)
Serial.println("Invalid Argument");
else if (result == ESP_ERR_ESPNOW_INTERNAL)
Serial.println("Internal Error");
else if (result == ESP_ERR_ESPNOW_NO_MEM)
Serial.println("ESP_ERR_ESPNOW_NO_MEM");
else if (result == ESP_ERR_ESPNOW_NOT_FOUND)
Serial.println("Peer not found.");
else
Serial.println("Not sure what happened");

}
// callback (automatically) when data is sent to master
void OnDataSent(const uint8_t* mac_addr, esp_now_send_status_t status) {
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
Serial.print("Last Packet Sent to: "); Serial.println(macStr);
Serial.print("Last Packet Send Status: "); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}


// callback (automatically) when data is received from Master
void OnDataRecv(const uint8_t* mac_addr, const uint8_t* data, int data_len) {
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
if (*data == 99)
requestData = true; //Flag send Data (Füllstand setzen)
else if(*data==88)
requestData2=true;

//Set Master Mac Adress to global Variable:
/*
for (int i = 0; i < 6; i++)
{
master.peer_addr[i] = mac_addr[i];
}
//memcpy(master.peer_addr, master_mac, 6); //set master mac adresse to defined value
*/

Serial.print("Last Packet Recv from: "); Serial.println(macStr);
Serial.print("Last Packet Recv Data: "); Serial.println(*data);
Serial.println("");
}

//Function to cast Array-Pointer: uint16_t Füllstandsarray[8] zu uint8_t Füllstandsarray[16]
//To send via ESP Now typ must be uint_8 (1 Byte) -> filling level (uint16_t) divided in 2 Bytes
void castToSend(uint16_t* Bit16Ptr, uint8_t* Bit8Ptr)
{
Bit8Ptr = (uint8_t*)Bit16Ptr;
}
//--------------------------------------------------------------------------------------------------------------
// ende esp now init

void init_scale() // alle scales anwesend? und calibrationfaktor und offset factor einschreiben
{

//Initialize all the sensors
for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
{
tcaselect(x);


if (myScale[x].begin() == false)
{
Serial.println("Scale not detected. Please check wiring. Freezing...");
Serial.println(x);
while (1);
}

Serial.println("Scale detected!");

myScale[x].setCalibrationFactor(calibfactor[x]);
myScale[x].setZeroOffset(offsetfactor[x]);


}
}


// VOID SETUP------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200); // Baudrate definieren
Serial.println("Qwiic Scale Example");
Wire.begin();
//änderung by user :-P
Wire.setClock(400000); //Qwiic Scale is capable of running at 400kHz if desired

//-----------------------------------------------------------------------------------------------------------
// setup esp now kommunikation (aus beispiel programm esp now
//Set device in AP mode to begin with
WiFi.mode(WIFI_AP);
// configure device AP mode
configDeviceAP();
// This is the mac address of the Slave in AP Mode
Serial.print("AP MAC: "); Serial.println(WiFi.softAPmacAddress());
// Init ESPNow with a fallback logic
InitESPNow();
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info.
esp_now_register_recv_cb(OnDataRecv); //Call receive Call Back function
esp_now_register_send_cb(OnDataSent); //Call send-callback-fkt //Copied from master example

//Master configurations:
memcpy(master.peer_addr, master_mac, 6); //set master mac adresse to defined value
master.ifidx = ESP_IF_WIFI_AP; //Set Master as AP!!! sending doesnt work if status is STA!!!
const esp_now_peer_info_t *peer = &master; //Cast auf const necessary
const uint8_t *peer_addr = master.peer_addr;

esp_err_t addStatus = esp_now_add_peer(peer); //Adding of master as peer
if (addStatus == ESP_OK) {
// Pair success
Serial.println("Pair success");
} else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT) {
// How did we get so far!!
Serial.println("ESPNOW Not Init");
} else if (addStatus == ESP_ERR_ESPNOW_ARG) {
Serial.println("Add Peer - Invalid Argument");
} else if (addStatus == ESP_ERR_ESPNOW_FULL) {
Serial.println("Peer list full");
} else if (addStatus == ESP_ERR_ESPNOW_NO_MEM) {
Serial.println("Out of memory");
} else if (addStatus == ESP_ERR_ESPNOW_EXIST) {
Serial.println("Peer Exists");
} else {
Serial.println("ADD Not sure what happened");
}

memcpy(master2.peer_addr, master_mac2, 6); //set master mac adresse to defined value
master2.ifidx = ESP_IF_WIFI_AP; //Set Master as AP!!! sending doesnt work if status is STA!!!
const esp_now_peer_info_t *peer2 = &master2; //Cast auf const necessary
const uint8_t *peer_addr2 = master2.peer_addr;

esp_err_t addStatus2 = esp_now_add_peer(peer2); //Adding of master as peer
if (addStatus2 == ESP_OK) {
// Pair success
Serial.println("Pair success");
} else if (addStatus2 == ESP_ERR_ESPNOW_NOT_INIT) {
// How did we get so far!!
Serial.println("ESPNOW Not Init");
} else if (addStatus2 == ESP_ERR_ESPNOW_ARG) {
Serial.println("Add Peer - Invalid Argument");
} else if (addStatus2 == ESP_ERR_ESPNOW_FULL) {
Serial.println("Peer list full");
} else if (addStatus2 == ESP_ERR_ESPNOW_NO_MEM) {
Serial.println("Out of memory");
} else if (addStatus2 == ESP_ERR_ESPNOW_EXIST) {
Serial.println("Peer Exists");
} else {
Serial.println("ADD Not sure what happened");
}
// ende esp now init
//-----------------------------------------------------------------------------------------------------------


//------------------------------NeoPixel starten---------------------------------------
pixels.begin(); //LED
pixels.show(); //LED
//---------------------------------------------------------------------------------


init_scale(); // initialisierung waagen
pinMode(Tare, INPUT);// initialisierung tare knopf auf pin 25
int Tarapin = digitalRead(Tare);
if (Tarapin) // wenn bei reset tare gedrückt gehalten wird gehe in tare gewicht für zusätzlichen offset (alle waargen müssen leer sein OHNE FLASCHEN!!!)
{
Serial.println("TARE FUNKTION");
taregewicht();
}
}


// LED Farben berechnen -------------------------------------------------------------------------------------------------
void LEDAusgabe(){
//Flasche 1
for (int i=0;i<8;i++)
{
if(Fuellgewicht[7-i] < 120)
{
LED_Farbe_0_255_int[7-i]=0;
}
else if((Fuellgewicht[7-i] >= 120) && (Fuellgewicht[7-i] <= Fuellgewicht_voll[7-i]))
{
LED_Farbe_0_255[7-i]=(Fuellgewicht[7-i])*255/(Fuellgewicht_voll[7-i]);//-Null_ml_Gewichte[7-i]
LED_Farbe_0_255_int[7-i]=((int)LED_Farbe_0_255[7-i]);

}
else
{
LED_Farbe_0_255_int[7-i]=255;
}
}
}
//---------------------Flaschen Fuellstand Ausgabe-----------------------------
void neoPixel() {
for(int8_t i=0; i<=NUMPIXELS; i++)
{
if(i<14)
{
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[7], LED_Farbe_0_255_int[7],0); //Flasche 7
if((LED_Farbe_0_255_int[7]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<22){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[6], LED_Farbe_0_255_int[6],0); //Flasche 6
if((LED_Farbe_0_255_int[6]==0)&& e%2 !=0)
{

pixels.setPixelColor(i,0,0,0);
}
}
else if(i<24)
pixels.setPixelColor(i,0,0,255); //blau
else if(i<31){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[5], LED_Farbe_0_255_int[5],0); //Flasche 5
if((LED_Farbe_0_255_int[5]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<34)
pixels.setPixelColor(i,0,0,255); //blau
else if(i<43){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[4], LED_Farbe_0_255_int[4],0); //Flasche 4
if((LED_Farbe_0_255_int[4]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<46)
pixels.setPixelColor(i,0,0,255); //blau 3
else if(i<56){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[3], LED_Farbe_0_255_int[3],0); //Flasche 3
if((LED_Farbe_0_255_int[3]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<59)
pixels.setPixelColor(i,0,0,255); //blau
else if(i<66){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[2], LED_Farbe_0_255_int[2],0); //Flasche 2
if((LED_Farbe_0_255_int[2]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<69)
pixels.setPixelColor(i,0,0,255); //blau
else if(i<77){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[1], LED_Farbe_0_255_int[1],0); //Flasche 1
if((LED_Farbe_0_255_int[1]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
//else if(i<81)
//pixels.setPixelColor(i,0,0,255); //blau
else if(i<91){
pixels.setPixelColor(i,255 - LED_Farbe_0_255_int[0], LED_Farbe_0_255_int[0],0); //Flasche 0
if((LED_Farbe_0_255_int[0]==0)&& e%2 !=0)
{
pixels.setPixelColor(i,0,0,0);
}
}
else if(i<NUMPIXELS)
pixels.setPixelColor(i,0,0,255); //blau
}
pixels.show();
e++;
if (e>=20)
{
e=0;
}
}

// ende LED ausgabe ----------------------------------------------------------------------------------------------


void loop()
{


for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++) // jeweils 8 werte zu von den Waagen holen und mitteln , in das Array eintragen und Null milliliter gewichte abziehen
{
tcaselect(x);
if (myScale[x].available() == true)
{
float currentReading = myScale[x].getWeight();
currentweight[x] = currentReading;
Fuellgewicht[7 - x] = currentweight[x] - Null_ml_Gewichte[x]-tarereading[x]; // aktuelles gewicht(mittelwert aus 8) minus null_ml_gewicht(wurde zuvor ermittelt und ist fix)-ggf zusätzlicher tarewert(tare pin)
if (Fuellgewicht[7 - x] < 0)
{
Fuellgewicht[7 - x] = 0;
}
stock[x] = (uint16_t)Fuellgewicht[x]; // cast von float auf Int zur übertragung
stock2[x]=(uint16_t)Fuellgewicht[x];
}


if (requestData) // wenn ein send request erhalten wurde gehe in senden funktion
{
sendStock();
}
else if(requestData2)
{
sendStock2();
}
}

// unsigned long CurrentTime = millis(); // delete later
// unsigned long ElapsedTime = CurrentTime - StartTime;// delete later
Serial.println(Fuellgewicht[7]);
Serial.println(Fuellgewicht[6]);
Serial.println(Fuellgewicht[5]);

Serial.println(Fuellgewicht[4]);
Serial.println(Fuellgewicht[3]);
Serial.println(Fuellgewicht[2]);
Serial.println(Fuellgewicht[1]);
Serial.println(Fuellgewicht[0]);
Serial.println("");


// LED Ausgabe aufrufen ---------------------------------------------------------------------
LEDAusgabe();
neoPixel();


}



ESP-Memory

main

/*
* Author: Felix Mezger(57667), Fabian Rogg(57667)
* Date: 27.03.2020
* Purpose: Stores the information of scaling ESP and sends this information to ESP Order
* Keep in mind, that ESP Memory is one of the two masters
*/
#include "ESPnow.h"


/* rofa */

extern bool transfer_data[];
extern bool handshake;
int counter= 0;

/* rofa */

bool flag_ESP_Bestellen= false;

cWifiESPNow myobject;



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


myobject.Init();
myobject.ScanForSlave();


}

void loop()
{

if( counter <4)
{
myobject.manageSlave();
myobject.requestStock();
counter++;

//delay(2000); // Break of 4 seconds, randomly

for( int i= 0; i<8; i++)
{
Serial.println("Werte von Transfer");
Serial.println(transfer_data[i]);


}


//delay(2000);

//if(Serial.read()== true)
if( handshake== true)
{
handshake= false;
flag_ESP_Bestellen= true;
//Serial.write(flag_ESP_Bestellen);

delay(1000);

//if(Serial.read()== true)
//{
for(int i=0;i<8;i++)
{
Serial.write(transfer_data[i]);
}
delay(1800);
//}
}
}
else
{

counter= 0;
ESP.restart();


}


delay(4000);

}












 

  Mit Unterstützung von Prof. J. Walter Sommersemester 2020