/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx_Server.h>

#include "NodeMCU_Common.h"


//
// Instantiate a TCP console
//
eCxx::TCPConsole tcpConsole;


//
// The init function
//
void eCxx_user_init()
{
    // Initialize application
    initBasicNodeMCUApp();

    // Initialize TCP console
    tcpConsole.begin();
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event
    eCxx::Application::processEvent();

    // Handle TCP console
    tcpConsole.handle();

    // Read from TCP console and write it back
    if( tcpConsole.canRead() ) {
        eCxx::uint8_t c;
        tcpConsole.read(c);

        tcpConsole.writeString( PGM_STR("Got: ") );
        tcpConsole.write(c);
        tcpConsole.write('\n');
    }
}
