So last night, I wanted to see if I could create three TX’s out of the Wemos D1. I was able to accomplish this using the TX/RX swapped to D7/D8, Pin D4 for UART1_TX_BK and USB-COM using TX (After swap is RTS / GPIO1). and Voila! Done. Something to note, With this change I then made my Runtime UART baud at 57600, Anything higher requires the chip to be accurate to a split of a MicroSecond which is difficult when as tiny as you can get us os_delay_us(1) which is a full MicroSecond thus jacking up the timing, at 57600 each bit is sent around 17.3US so being .3 off isn’t too bad compared to being off by .3 when only have 8US sleep time between bits, The error adds up at the end of the 8 bits that can really jack with your result.

Softuart.h

#ifndef SoftUART_APP_H
#define SoftUART_APP_H

static inline u8 chbit(u8 data, u8 bit)
{
    if ((data & bit) != 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

void sendUART(int GPIO, int command[], int sizeofcmd, long baud) //Did not work
{
    int i=0;
    int ii=0;
    system_soft_wdt_feed();

    for (i=0; i<sizeofcmd; i++)
    {
        gpio_output_set(0, (1 << 2), (1 << 2), 0);
        os_delay_us(7);
        for(ii = 0; ii < 8; ii ++ )
        {

            if (chbit(command[i],1<<ii))
            {
                gpio_output_set((1 << 2), 0, (1 << 2), 0);              
                //GPIO_OUTPUT_SET((1 << GPIO), chbit('T',1<<i));
                //os_printf("on");
            }           
            else
            {
                gpio_output_set(0, (1 << 2), (1 << 2), 0);
                //GPIO_OUTPUT_SET((1 << GPIO), chbit('T',1<<i));
                //os_printf("off");
            }
            os_delay_us(7);
        }
        gpio_output_set((1 << 2), 0, (1 << 2), 0);
        //os_delay_us(4);
        //system_soft_wdt_feed();
    }
    //os_printf("\r\nSignal sent\r\n");
}

static int soft_uart_putchar_c(int GPIO, unsigned bit_time, char data)
{
    unsigned i;
    unsigned start_time = 0x7FFFFFFF & system_get_time();

    //Start Bit
    gpio_output_set(0, (1 << GPIO), 0, 0); //LOW
    for(i = 0; i <= 8; i ++ )
    {
        while ((0x7FFFFFFF & system_get_time()) < (start_time + (bit_time*(i+1))))
        {
            //If system timer overflow, escape from while loop
            if ((0x7FFFFFFF & system_get_time()) < start_time){break;}
        }
        GPIO_OUTPUT_SET(GPIO_ID_PIN(GPIO), chbit(data,1<<i)); //if GPIO_OUTPUT_SET is all capped it's calling the Macro, if not it's calling a different api
    }

    // Stop bit
    while ((0x7FFFFFFF & system_get_time()) < (start_time + (bit_time*9)))
    {
        //If system timer overflow, escape from while loop
        if ((0x7FFFFFFF & system_get_time()) < start_time){break;}
    }
    gpio_output_set((1 << GPIO), 0, 0, 0);
    // Delay after byte, for new sync
    os_delay_us(bit_time*6);
    return 1;
}

void convert2hex(char buffer[], int length)
{
    int i=0;
    char itoabuffer[4];

    int s=0;
    for(; s < length; ++s )
    {
        if ((buffer[s] < 32) || (buffer[s] > 126))
        {
            os_printf("\\x");
            os_sprintf(itoabuffer, "%X", buffer[s]);            
            for(i=0; i < strlen(itoabuffer); ++i )
            {
                os_printf("%c", itoabuffer[i]);
            }
        }
        else
        {
            os_printf("%c", buffer[s]);
        }
    }
}

//You can call this with the following line to redirect PrintF after a UART Swap
//os_install_putc1((void *)USBRTS_BAUD57600_write_char); //Redirect OS_PRINTF to UART1, our debug port
LOCAL void ICACHE_FLASH_ATTR USBRTS_BAUD57600_write_char(char c)
{
    const unsigned bit_time = (1000000 / 57600);
    if (c == '\n')
    {
        soft_uart_putchar_c(1, bit_time, '\r');
        soft_uart_putchar_c(1, bit_time, '\n');
    }
    else if (c == '\r')
    {
    }
    else
    {
        soft_uart_putchar_c(1, bit_time, c);
    }
}

LOCAL void ICACHE_FLASH_ATTR USBRTS_BAUD57600_write_charToHex(char c)
{
    int i=0;
    char itoabuffer[4];
    if (((c < 32) || (c > 126)) && ((c != 10) && (c != 13)))
    {
        //os_printf("\\x");
        USBRTS_BAUD57600_write_char('\\');
        USBRTS_BAUD57600_write_char('x');
        os_sprintf(itoabuffer, "%X", c);            
        for(i=0; i < strlen(itoabuffer); ++i )
        {
            //os_printf("%c", itoabuffer[i]);
            USBRTS_BAUD57600_write_char(itoabuffer[i]);
        }
    }
    else
    {
        //os_printf("%c", c);
        USBRTS_BAUD57600_write_char(c);
    }
}

int softuart_write(int GPIO, const char* data, unsigned len, long baudrate )
{
    //const unsigned baudrate = 57600; //Highest I've been able to go is 57600 Baud, 115200 misses some but 74880 misses alot
    const unsigned bit_time = (1000000 / baudrate);

    gpio_output_set((1 << GPIO), 0, 0, 0); //High
    os_delay_us(bit_time*8);
    int s=0;
    for(; s < len; ++s )
    {
        soft_uart_putchar_c(GPIO, bit_time, data[ s ]);
    }
    return 0;
}
#endif

main.c

//https://www.mikrocontroller.net/attachment/263828/The-ESP8266-Book-August-2015.pdf
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "ip_addr.h"
#include "mem.h"
#include "user_interface.h"
#include "lwip/stats.h"
#include "espconn.h"

#include "c_types.h" ////ONE WIRE

#include "../library/uart.h" //Copy these from your Driver Lib to your local folder
#include "../library/gpio16.h" //Copy these from your Driver Lib to your local folder

#include "../library/softuart.h"
#include "../library/common.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1
os_event_t user_procTaskQueue[user_procTaskQueueLen];

void uart0_tx_buffer(uint8 *buf, uint16 len);

char rxbuff[31];
char rxindex = 0;

void UartReceive(char ByteReceived)
{
    os_printf("[%s] Got UART Callback!\r\n", __func__);
    os_printf("Byte Recevied: %c\r\n", ByteReceived);

    rxbuff[rxindex++] = ByteReceived;
    if (rxindex == sizeof(rxbuff)) 
    {
        rxindex = 0;
    }
    else
    {
        os_printf("%d != %d\r\n", rxindex, sizeof(rxbuff));
    }
    os_printf("Buffer: %s\r\n", rxbuff);

    hex_printf(rxbuff,rxindex);
    return;
}

void ICACHE_FLASH_ATTR sdk_init_done_cb(void) 
{ 
    os_printf("[%s] initializing ESP8266!\n", __func__);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); //Set GPIO1(TX) as a manual GPIO Pin
    gpio_output_set((1 << 1), 0, (1 << 1), 0); //Set Pin as an OUT and Set it High
    while(true)
    {
        os_printf("test");
        uart0_tx_buffer("page 1\xff\xff\xff", 9); //This is our Prod Port
        uart1_tx_buffer("page 2\xff\xff\xff", 9); //This is our Debug Port
        softuart_write(1, "This is a test\r\n", 17, 57600); //This is our USB-COM Port
        delay_second();
        delay_second();
    }
}

void ICACHE_FLASH_ATTR SetupUART(void)
{
    //Careful when the callback is triggered that it does not kick off any premature events like sending network packets before the network is connected, thus crashing your app
    uart_init(BIT_RATE_57600, BIT_RATE_57600, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
    system_set_os_print(1); //Turns os_PrintF Log Printing On or Off
    //We use UART swap because the RXpin is always High from external outputs causing issues when loading new firmware.
    //Keep in mind uart swap only swaps the RTS and CTS of the same UART to the RX and TX of the same UART, NOT UART1 to UART0
    //"UART0 swap. Use MTCK as UART0 Rx, MTDO as UART0 Tx, so ROM log will not output from this new UART0. MTDO (U0RTS) and MTCK (U0CTS) also need to be used as UART0 in hardware
    system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart - Makes D7 RX (MTCK) and D8 TX (MTDO)

    //Pick here where you want PrintF to output
//os_install_putc1((void *)uart1_write_char); //Redirect OS_PRINTF to UART1 (D4)
//os_install_putc1((void *)USBRTS_BAUD57600_write_char); //Redirect OS_PRINTF to USBCOMM, our debug port
os_install_putc1((void *)USBRTS_BAUD57600_write_charToHex); //Redirect OS_PRINTF to USBCOMM, our debug port Plus converting nonreadable to hex
}

void ICACHE_FLASH_ATTR user_init()
{
    SetupUART();

    system_init_done_cb(sdk_init_done_cb);

    wifi_set_opmode(0);
    wifi_set_sleep_type( NONE_SLEEP_T );

    ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts
    gpio_init();    

    SetAllGPIOPinsAsOutput();

    /* Need to fix this to display value    */
    uint32 VDDADCByte[4] = {0};
    spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF

    os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));

    //Turn off LED, We cannot touch this pin as this is our debug pin D4/GPIO2
    //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
    //gpio_output_set((1 << 2), 0, 0, 0);

    //Start os task
    system_init_done_cb(sdk_init_done_cb);
    //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
}

uart.h

/*
 * ESPRSSIF MIT License
 *
 * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
 *
 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
 * it is free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef UART_APP_H
#define UART_APP_H

#include "uart_register.h"
#include "eagle_soc.h" //~/esp-open-sdk/xtensa-lx106-elf/sysroot/usr/include <-- pulled from here
#include "c_types.h"
#include "pin_mux_register.h"
//#include "task.h"
#define recvTaskPrio        0
#define recvTaskQueueLen    64

#define UART_BUFF_EN  0   //use uart buffer  , FOR UART0
#define UART_SELFTEST  0  //set 1:enable the loop test demo for uart buffer, FOR UART0

#define UART_HW_RTS   0   //set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0
#define UART_HW_CTS  0    //set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0

#define UART0   0
#define UART1   1

//calc bit 0..5 for  UART_CONF0 register
#define CALC_UARTMODE(data_bits,parity,stop_bits) \
    (((parity == NONE_BITS) ? 0x0 : (UART_PARITY_EN | (parity & UART_PARITY))) | \
    ((stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S) | \
    ((data_bits & UART_BIT_NUM) << UART_BIT_NUM_S))
//get data_bits from UART_CONF0 register
#define GETUART_DATABITS(uartmode) ((uartmode >> UART_BIT_NUM_S) & UART_BIT_NUM)
//get stop_bits from UART_CONF0 register
#define GETUART_STOPBITS(uartmode) ((uartmode >> UART_STOP_BIT_NUM_S) & UART_STOP_BIT_NUM)
//get parity from UART_CONF0 register
#define GETUART_PARITYMODE(uartmode) ((uartmode & UART_PARITY_EN) ? uartmode & UART_PARITY : NONE_BITS)


typedef enum {
    FIVE_BITS = 0x0,
    SIX_BITS = 0x1,
    SEVEN_BITS = 0x2,
    EIGHT_BITS = 0x3
} UartBitsNum4Char;

typedef enum {
    ONE_STOP_BIT             = 0x1,
    ONE_HALF_STOP_BIT        = 0x2,
    TWO_STOP_BIT             = 0x3
} UartStopBitsNum;

typedef enum {
    NONE_BITS = 0x2,
    ODD_BITS   = 1,
    EVEN_BITS = 0
} UartParityMode;

typedef enum {
    STICK_PARITY_DIS   = 0,
    STICK_PARITY_EN    = 1
} UartExistParity;

typedef enum {
    UART_None_Inverse = 0x0,
    UART_Rxd_Inverse = UART_RXD_INV,
    UART_CTS_Inverse = UART_CTS_INV,
    UART_Txd_Inverse = UART_TXD_INV,
    UART_RTS_Inverse = UART_RTS_INV,
} UART_LineLevelInverse;


typedef enum {
    BIT_RATE_300 = 300,
    BIT_RATE_600 = 600,
    BIT_RATE_1200 = 1200,
    BIT_RATE_2400 = 2400,
    BIT_RATE_4800 = 4800,
    BIT_RATE_9600   = 9600,
    BIT_RATE_19200  = 19200,
    BIT_RATE_38400  = 38400,
    BIT_RATE_57600  = 57600,
    BIT_RATE_74880  = 74880,
    BIT_RATE_115200 = 115200,
    BIT_RATE_230400 = 230400,
    BIT_RATE_460800 = 460800,
    BIT_RATE_921600 = 921600,
    BIT_RATE_1843200 = 1843200,
    BIT_RATE_3686400 = 3686400,
} UartBautRate;

typedef enum {
    NONE_CTRL,
    HARDWARE_CTRL,
    XON_XOFF_CTRL
} UartFlowCtrl;

typedef enum {
    USART_HardwareFlowControl_None = 0x0,
    USART_HardwareFlowControl_RTS = 0x1,
    USART_HardwareFlowControl_CTS = 0x2,
    USART_HardwareFlowControl_CTS_RTS = 0x3
} UART_HwFlowCtrl;

typedef enum {
    EMPTY,
    UNDER_WRITE,
    WRITE_OVER
} RcvMsgBuffState;

typedef struct {
    uint32     RcvBuffSize;
    uint8     *pRcvMsgBuff;
    uint8     *pWritePos;
    uint8     *pReadPos;
    uint8      TrigLvl; //JLU: may need to pad
    RcvMsgBuffState  BuffState;
} RcvMsgBuff;

typedef struct {
    uint32   TrxBuffSize;
    uint8   *pTrxBuff;
} TrxMsgBuff;

typedef enum {
    BAUD_RATE_DET,
    WAIT_SYNC_FRM,
    SRCH_MSG_HEAD,
    RCV_MSG_BODY,
    RCV_ESC_CHAR,
} RcvMsgState;

typedef struct {
    UartBautRate         baut_rate;
    UartBitsNum4Char  data_bits;
    UartExistParity      exist_parity;
    UartParityMode      parity;    
    UartStopBitsNum   stop_bits;
    UartFlowCtrl         flow_ctrl;
    RcvMsgBuff          rcv_buff;
    TrxMsgBuff           trx_buff;
    RcvMsgState        rcv_state;
    int                      received;
    int                      buff_uart_no;  //indicate which uart use tx/rx buffer
} UartDevice;

//void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, void * callback);
void uart0_sendStr(const char *str);


///////////////////////////////////////

 struct UartBuffer{
    uint32     UartBuffSize;
    uint8     *pUartBuff;
    uint8     *pInPos;
    uint8     *pOutPos;
    STATUS  BuffState;
    uint16    Space;  //remanent space of the buffer
    uint8  TcpControl;
    struct  UartBuffer     *  nextBuff;
};

struct UartRxBuff{
    uint32     UartRxBuffSize;
    uint8     *pUartRxBuff;
    uint8     *pWritePos;
    uint8     *pReadPos;
    STATUS RxBuffState;
    uint32    Space;  //remanent space of the buffer
} ;

typedef enum {
    RUN = 0,
    BLOCK = 1,
} TCPState;

//void ICACHE_FLASH_ATTR uart_test_rx();
//STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar);
void  uart1_sendStr_no_wait(const char *str);
struct UartBuffer*  Uart_Buf_Init();


#if UART_BUFF_EN
LOCAL void  Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len);
void  uart_buf_free(struct UartBuffer* pBuff);
void  tx_buff_enq(char* pdata, uint16 data_len );
LOCAL void  tx_fifo_insert(struct UartBuffer* pTxBuff, uint8 data_len,  uint8 uart_no);
void  tx_start_uart_buffer(uint8 uart_no);
uint16  rx_buff_deq(char* pdata, uint16 data_len );
void  Uart_rx_buff_enq();
#endif
void  uart_rx_intr_enable(uint8 uart_no);
void  uart_rx_intr_disable(uint8 uart_no);
void uart0_tx_buffer(uint8 *buf, uint16 len);

//==============================================
#define FUNC_UART0_CTS 4
#define FUNC_U0CTS                      4
#define FUNC_U1TXD_BK                   2
#define UART_LINE_INV_MASK  (0x3f<<19)
void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len);
void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num);
void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask);
void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode);
void UART_SetBaudrate(uint8 uart_no,uint32 baud_rate);
void UART_SetFlowCtrl(uint8 uart_no,UART_HwFlowCtrl flow_ctrl,uint8 rx_thresh);
void UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us); //do not use if tx flow control enabled
void UART_ResetFifo(uint8 uart_no);
void UART_ClearIntrStatus(uint8 uart_no,uint32 clr_mask);
void UART_SetIntrEna(uint8 uart_no,uint32 ena_mask);
void UART_SetPrintPort(uint8 uart_no);
bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us);
//==============================================

#endif




/*
 * File : uart.c
 * This file is part of Espressif's AT+ command set program.
 * Copyright (C) 2013 - 2016, Espressif Systems
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of version 3 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*#include "ets_sys.h"
#include "osapi.h"
#include "driver/uart.h"
#include "osapi.h"
#include "driver/uart_register.h"
//#include "ssc.h"
#include "task.h"
*/
// UartDev is defined and initialized in rom code.
extern UartDevice    UartDev;
//extern os_event_t    at_recvTaskQueue[at_recvTaskQueueLen];

LOCAL void uart0_rx_intr_handler(void *para);

/******************************************************************************
 * FunctionName : uart_config
 * Description  : Internal used function
 *                UART0 used for data TX/RX, RX buffer size is 0x100, interrupt enabled
 *                UART1 just used for debug output
 * Parameters   : uart_no, use UART0 or UART1 defined ahead
 * Returns      : NONE
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no, void * callback(uint8))
{
    os_printf("uart_config:%d", uart_no);
    if (uart_no == UART0)
    {
        /* UART0 */
        ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  callback);
        PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
        //Enable RxD pin
        PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);        
        //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); //We don't use RTS
    }
    else
    {
        PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); //D4 used for Debug out.
        PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
    }

    uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));

    WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT));

    //clear rx and tx fifo,not ready
    SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
    CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);

    WRITE_PERI_REG(UART_CONF1(uart_no), ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));

    //clear all interrupt
    WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
    //enable rx_interrupt
    SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA);
}

/******************************************************************************
 * FunctionName : uart1_tx_one_char
 * Description  : Internal used function
 *                Use uart1 interface to transfer one char
 * Parameters   : uint8 TxChar - character to tx
 * Returns      : OK
*******************************************************************************/
LOCAL STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
{
    while (true)
    {
      uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT<<UART_TXFIFO_CNT_S);
      if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) {
        break;
      }
    }

    WRITE_PERI_REG(UART_FIFO(uart) , TxChar);
    return OK;
}

/******************************************************************************
 * FunctionName : uart1_write_char
 * Description  : Internal used function
 *                Do some special deal while tx char is '\r' or '\n'
 * Parameters   : char c - character to tx
 * Returns      : NONE
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR uart1_write_char(char c)
{
  if (c == '\n')
  {
    uart_tx_one_char(UART1, '\r');
    uart_tx_one_char(UART1, '\n');
  }
  else if (c == '\r')
  {
  }
  else
  {
    uart_tx_one_char(UART1, c);
  }
}
/******************************************************************************
 * FunctionName : uart0_tx_buffer
 * Description  : use uart0 to transfer buffer
 * Parameters   : uint8 *buf - point to send buffer
 *                uint16 len - buffer len
 * Returns      :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_tx_buffer(uint8 *buf, uint16 len)
{
  uint16 i;

  for (i = 0; i < len; i++)
  {
    uart_tx_one_char(UART0, buf[i]);
  }
}

/******************************************************************************
 * FunctionName : uart0_tx_buffer
 * Description  : use uart0 to transfer buffer
 * Parameters   : uint8 *buf - point to send buffer
 *                uint16 len - buffer len
 * Returns      :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart1_tx_buffer(uint8 *buf, uint16 len)
{
  uint16 i;

  for (i = 0; i < len; i++)
  {
    uart_tx_one_char(UART1, buf[i]);
  }
}

/******************************************************************************
 * FunctionName : uart0_sendStr
 * Description  : use uart0 to transfer buffer
 * Parameters   : uint8 *buf - point to send buffer
 *                uint16 len - buffer len
 * Returns      :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str)
{
    while(*str)
    {
        uart_tx_one_char(UART0, *str++);
    }
}

/******************************************************************************
 * FunctionName : uart0_rx_intr_handler
 * Description  : Internal used function
 *                UART0 interrupt handler, add self handle code inside
 * Parameters   : void *para - point to ETS_UART_INTR_ATTACH's arg
 * Returns      : NONE
*******************************************************************************/
typedef void (*UARTFunctionCallback)(char ByteReceived);
UARTFunctionCallback UARTCallback;

LOCAL void uart0_rx_intr_handler(void * para)
{
    char RcvChar[0];

    //If I remove pRXbuff my program crashes, This may be due to not enough stackspace
    RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; //This is now a Callback pointer

    if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
        return;
    }

    WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);

    while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) 
    {
        ETS_UART_INTR_DISABLE();
        RcvChar[0] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;        
        /* you can add your handle code below.*/

        UARTCallback = para;
        UARTCallback(RcvChar[0]);
        /*
        gpio_output_set((1 << 2), 0, 0, 0);
        uart0_tx_buffer(RcvChar, 1);
        if (RcvChar[0] == '\n') 
        {
            gpio_output_set(0, (1 << 2), 0, 0);
            uart0_sendStr("\r\nGot enter N\r\n");
        }
        if (RcvChar[0] == '\r') 
        {
            gpio_output_set(0, (1 << 2), 0, 0);
            uart0_sendStr("\r\nGot enter R\r\n");
        }
        */
         // Clear pending FIFO interrupts
        WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST);
        ETS_UART_INTR_ENABLE();
    }
}

/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR uart_init(UartBautRate uart0_br, UartBautRate uart1_br, void * callback)
{
    // rom use 74880 baut_rate, here reinitialize
    UartDev.baut_rate = uart0_br;
    uart_config(UART0, callback);

    UartDev.baut_rate = uart1_br;
    uart_config(UART1, callback);

    ETS_UART_INTR_ENABLE();

    // install uart1 putc callback
    //system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart
    //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
    //os_install_putc1((void *)uart1_write_char);
}

void ICACHE_FLASH_ATTR uart_reattach()
{
    uart_init(BIT_RATE_74880, BIT_RATE_74880, NULL);
//  ETS_UART_INTR_ATTACH(uart_rx_intr_handler_ssc,  &(UartDev.rcv_buff));
//  ETS_UART_INTR_ENABLE();
}

Using the following code I was able to push Firewall settings to multiple machines.

#https://gallery.technet.microsoft.com/scriptcenter/xNetworking-Module-818b3583
Configuration ScriptTest
{
    param
    (
        [string[]] $NodeName = 'Localhost'
    )

    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
    Node $NodeName
    {
        Script EnableFirewall            
        {            
            # Must return a hashtable with at least one key            
            # named 'Result' of type String            
            GetScript = {            
                Return @{            
                    Result = [string]$(netsh advfirewall show allprofiles)            
                }            
            }            

            # Must return a boolean: $true or $false            
            TestScript = {            
                If ((netsh advfirewall show allprofiles) -like "State*off*") {            
                    Write-Verbose "One or more firewall profiles are off"            
                    Return $false            
                } Else {            
                    Write-Verbose "All firewall profiles are on"            
                    Return $false #return false as well to always run the SetScript on the remote server            
                }            
            }            

            # Returns nothing            
            SetScript = {            
                Write-Verbose "Setting all firewall profiles to on"            
                #netsh advfirewall set allprofiles state on
                Remove-NetFirewallRule -All            
            }            
        }            
    }      

    }
}

Configuration DSCFirewallRule
{
    param
    (
        [string[]] $NodeName = 'Localhost'
    )

    Import-DSCResource -ModuleName xNetworking

    Node $NodeName
    {
        xFirewall Firewall1 
        {
            Access      = 'Block'
            Name        = 'NotePadFirewallRule'
            DisplayName = 'Firewall Rule for Notepad.exe'
            Ensure      = 'Present'
            Profile     = ('Domain', 'Private')
            Direction   = 'OutBound'
            RemotePort  = ('8080', '8081')
            LocalPort   = ('9080', '9081')
            Protocol    = 'TCP'
            Description = 'Firewall Rule for Notepad.exe'
            Service = 'WinRM'
            State = 'Enabled'
        }

        xFirewall Firewall2 
        {
            Access      = 'Allow'
            Name        = 'NotePad++FirewallRule'
            DisplayName = 'Firewall Rule for Notepad++.exe'
            Ensure      = 'Present'
            Profile     = ('Domain', 'Private')
            Direction   = 'OutBound'
            RemotePort  = ('8082', '8084')
            LocalPort   = ('9086', '9085')
            Protocol    = 'TCP'
            Description = 'Firewall Rule for Notepad++.exe'
            Service = 'WinRM'
            State = 'Enabled'
        }

    }

}

#You only need to create checksums for PULL HTTP(s) methods
New-DSCCheckSum –ConfigurationPath .\SimpleMetaConfigurationForPull –OutPath .\ScriptTest -Verbose -Force
New-DSCCheckSum –ConfigurationPath .\SimpleMetaConfigurationForPull –OutPath .\DSCFirewallRule -Verbose -Force
ScriptTest –nodename ‘LocalHost’,‘server1’,’server2’,’server3’ #Creates a folder with that name
DSCFirewallRule –nodename ‘LocalHost’,‘server1’,’server2’,’server3’ #Creates a folder with that name

#Push the configuration to the Target nodes, Comment this out if your just generating the MOF(s) for a pull method.
Start-DscConfiguration -Path .\ScriptTest -Wait -Force -Verbose #Clears Firewall Rules
Start-DscConfiguration -Path .\DSCFirewallRule -Wait -Force -Verbose #Sets them

Now the following script above will create .MOF files that will then Now we have to create a Pull Server. Well have to do it like this for Server 2008R2

Src: https://davewyatt.wordpress.com/2014/06/07/how-to-install-a-dsc-pull-server-on-windows-2008-r2/

Or for Server 2012

configuration CreatePullServer
{
    param
    (
        [string[]]$ComputerName = 'localhost'
    )


Import-DSCResource -ModuleName xPSDesiredStateConfiguration


Node $ComputerName
{
    WindowsFeature DSCServiceFeature
    {
        Ensure = "Present"
        Name   = "DSC-Service"
    }


    xDscWebService PSDSCPullServer
    {
        Ensure = "Present"
        EndpointName = "PSDSCPullServer" 
                Port = 8080 
                PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" 
                CertificateThumbPrint = "AllowUnencryptedTraffic" 
                ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" 
                ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" 
                State = "Started" 
                DependsOn = "[WindowsFeature]DSCServiceFeature" 
        } 

    xDscWebService PSDSCComplianceServer 
        { 
            Ensure = "Present" 
            EndpointName = "PSDSCComplianceServer" 
            Port = 9080 
            PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer" 
            CertificateThumbPrint = "AllowUnencryptedTraffic" 
            State = "Started"
            IsComplianceServer = $true 
            DependsOn = ("[WindowsFeature]DSCServiceFeature", 
                                       "[xDSCWebService]PSDSCPullServer") 
        } 
    } 
}

CreatePullServer

After the pull server is created I also had to make an adjustment to fix a 500 internal error I was getting from the above script on Server 2012 R2 https://stackoverflow.com/questions/24252635/powershell-dsc-pull-server-throws-internal-error-microsoft-isam-esent-interop

Now the last step is to push the configuration to each machine to tell each machine to check in to the web server hosting the MOF configuration files..

Configuration SimpleMetaConfigurationForPull
{
    param
    (
        [string[]] $NodeName = 'Localhost'
    )
    Node $NodeName
    {
        LocalConfigurationManager
        {
            RefreshMode = “PULL”;
            DownloadManagerName = “WebDownloadManager”;
            RebootNodeIfNeeded = $true;
            RefreshFrequencyMins = 10;
            ConfigurationModeFrequencyMins = 15;
            ConfigurationMode = “ApplyAndAutoCorrect”;
            ConfigurationID = $NodeName
            DownloadManagerCustomData = @{ServerUrl = “http://VM1198:8080/PSDSCPullServer/psdscpullserver.svc”; AllowUnsecureConnection = “TRUE”}
        }
    }
} 
SimpleMetaConfigurationForPull -Output .\SimpleMetaConfigurationForPull –nodename ‘LocalHost’,‘server1’,’server2’,’server3’
New-DSCCheckSum –ConfigurationPath .\SimpleMetaConfigurationForPull –OutPath .\SimpleMetaConfigurationForPull -Verbose -Force
Set-DSCLocalConfigurationManager -Path .\SimpleMetaConfigurationForPull –Verbose

As you can see the machine is checking in every 15 minutes per our script.

So, The Wemos D1 Mini pro is the board I use to program the NONOS SDK right now currently. The downside is it only exposes one UART interface (UART0) and with that comes some minor issues.
1: If you connect an FTDI chip to this port the TX line from the FTDI is always HIGH and will keep the RX Pin on the ESP8266 HIGH and will stop new firmware from being loaded until you physically disconnect the FTDI chip.

2: The Line is not dedicated so sending Debug in on this line may interfere with other external devices connected to this line.

So the first issue is solved by calling system_uart_swap() thus swapping the RX/TX line with D7 and D8 for the RTS CTS lines freeing the TX/RX labeled pins on the Wemos

The 2nd one can use GPIO2 and use UART1 to transmit the data.

LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no, void * callback(uint8))
{
    os_printf("uart_config:%d", uart_no);
    if (uart_no == UART0)
    {
        /* UART0 */
        ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  callback);
        PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
        //Enable RxD pin
        PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);        
        //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); //We don't use RTS
    }
    else
    {
        PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); //D4 used for Debug out.
        PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
    }

    uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));

    WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT));

    //clear rx and tx fifo,not ready
    SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
    CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);

    WRITE_PERI_REG(UART_CONF1(uart_no), ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));

    //clear all interrupt
    WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
    //enable rx_interrupt
    SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA);
}

void ICACHE_FLASH_ATTR uart_init(UartBautRate uart0_br, UartBautRate uart1_br, void * callback)
{
    // rom use 74880 baut_rate, here reinitialize
    UartDev.baut_rate = uart0_br;
    uart_config(UART0, callback);

    UartDev.baut_rate = uart1_br;
    uart_config(UART1, callback);

    ETS_UART_INTR_ENABLE();

    // install uart1 putc callback
    //system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart
    //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
    //os_install_putc1((void *)uart1_write_char);
}

void ICACHE_FLASH_ATTR sdk_init_done_cb(void) 
{ 
    os_printf("[%s] initializing ESP8266!\n", __func__);
    while(true)
    {
        os_printf("test");
        uart0_tx_buffer("page 1\xff\xff\xff", 9); //This is our Prod Port
        uart1_tx_buffer("page 2\xff\xff\xff", 9); //This is our Debug Port
        delay_second();
        delay_second();
    }
}

void ICACHE_FLASH_ATTR SetupUART(void)
{
    //Careful when the callback is triggered that it does not kick off any premature events like sending network packets before the network is connected, thus crashing your app
    uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
    system_set_os_print(1); //Turns os_PrintF Log Printing On or Off
    //We use UART swap because the RXpin is always High from external outputs causing issues when loading new firmware.
    //Keep in mind uart swap only swaps the RTS and CTS of the same UART to the RX and TX of the same UART, NOT UART1 to UART0
    //"UART0 swap. Use MTCK as UART0 Rx, MTDO as UART0 Tx, so ROM log will not output from this new UART0. MTDO (U0RTS) and MTCK (U0CTS) also need to be used as UART0 in hardware
    system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart - Makes D7 RX (MTCK) and D8 TX (MTDO)
    os_install_putc1((void *)uart1_write_char); //Redirect OS_PRINTF to UART1, our debug port
}

void ICACHE_FLASH_ATTR user_init()
{
    SetupUART();

    system_init_done_cb(sdk_init_done_cb);

    wifi_set_opmode(0);
    wifi_set_sleep_type( NONE_SLEEP_T );

    ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts
    gpio_init();    

    SetAllGPIOPinsAsOutput();

    /* Need to fix this to display value    */
    uint32 VDDADCByte[4] = {0};
    spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF

    os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));

    //Turn off LED, We cannot touch this pin as this is our debug pin D4/GPIO2
    //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
    //gpio_output_set((1 << 2), 0, 0, 0);

    //Start os task
    system_init_done_cb(sdk_init_done_cb);
    //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
}

First download NUGet from NuGet.org.
Install it for your cordinating version of visual studio

Once installed Launch VS then launch NuGet’s console from within

Run the following line for Framework 4.0 and Above
PM> Install-Package ASTreeView

If your project is targeted to .Net Framework 2.0 or 3.5, please install the legacy package using this line below instead.
PM> Install-Package ASTreeView.Legacy

Once ran add the reference to the project, The path to the DLL looked like this

C:\Users[username]\Documents\Visual Studio 2015\Projects\ASPTreeDragAndDrop\packages\ASTreeView.1.6.0.4\lib\net40

Then after that add the utilities to the toolbox.

Now you can start adding your tree and design your Drag and Drop Functionality.

So once in a while, I get a stingy program that refuses to remove itself from my Add Or Remove Program’s list.

So what I end up doing is jumping into the registry and removing the Key from the uninstall list.
In my case, I ended up having to remove a couple of keys under that list to fully rip it out of AppWiz.

And the final result.

So, My hearing was on Friday the 15th. It turns out that they have up to three days to enter the minutes from the hearing and that I’ll receive an update by the end of this week in the mail. Fingers crossed 🙂

Update Minutes were posted today. Took about a business day and a half. Friday to Monday Noonish.

Previous Post: http://controllingtheinter.net/2018/03/07/appellees-opening-brief-response-from-district-attorneys-office/

Our department is pretty large and users tend to change user folder permissions out of our standard. This script I threw together to cycle through a list of folders that match the users ‘samAccountName’ in active directory. BEWARE This will delete folders and data of users that do not exist.

Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host

$Domain = "MyDomain"

$RootFSPath = "G:\users3"

Function GetFolderACL([string]$User, [bool]$Recursive) 
{
    $filePath = "$RootFSPath\$User"
    #Get-Acl -Path $filePath | Format-List
    $filePathacl = Get-Acl -Path $filePath
    if ($Recursive -eq $True)
    {
        $folders = Get-ChildItem $filePath -Recurse #-Directory
        foreach ($folder in $folders)
        {
            #Get-Acl -Path $folder.FullName | Format-List
            foreach ($access in $filePathacl.Access) 
            {
                if ($access.IdentityReference.Value -eq "$Domain\$user" -and $access.FileSystemRights -eq "Modify, Synchronize") 
                {
                    continue
                }
                if ($access.IdentityReference.Value -eq "NT AUTHORITY\SYSTEM" -and $access.FileSystemRights -eq "FullControl") 
                {
                    continue
                }
                if ($access.IdentityReference.Value -eq "BUILTIN\Administrators" -and $access.FileSystemRights -eq "FullControl") 
                {
                    continue
                }
                if ($access.IdentityReference.Value -eq "$Domain\Domain Admins" -and $access.FileSystemRights -eq "FullControl") 
                {
                    continue
                }
                Write-Host $access.IdentityReference $access.FileSystemRights
            }
        }
    }
}

Function GetFolderACLRecursive([string]$filePath, [string]$User,[bool]$Recursive) 
{

    if ($Recursive -eq $True)
    {
        $folders = Get-ChildItem $filePath -Recurse -Directory
        foreach ($folder in $folders)
        {
            GetFolderACLRecursive $folder.PSPath $true
        }
    }

    [bool]$UserPerm = $false
    [bool]$SystemPerm = $false
    [bool]$AdminPerm = $false
    [bool]$DomainAdminPerm = $false

    $Searcher = [ADSISearcher]"(sAMAccountName=$folder)"
    $Results = $Searcher.FindOne()

    If ($Results -eq $Null) 
    {
        if ($filePath -ne "$RootFSPath\")
        {
            #try your best not to wak the parent folder due to Hr's typeo's ;)
            Write-Host "$folder does not exist in AD, $filePath can be deleted... Deleting"
            Remove-Item –path $filePath –recurse -force
            $UserPerm = $true
        }
    }
    else #If they do exit check the ACLS
    {
        $filePathacl = Get-Acl -Path $filePath
        foreach ($access in $filePathacl.Access) 
        {
            if ($access.IdentityReference.Value -eq "$Domain\$User" -and $access.FileSystemRights -eq "Modify, Synchronize") 
            {
                $UserPerm = $true
                continue
            }
            if ($access.IdentityReference.Value -eq "NT AUTHORITY\SYSTEM" -and $access.FileSystemRights -eq "FullControl") 
            {
                $SystemPerm = $true
                continue
            }
            if ($access.IdentityReference.Value -eq "BUILTIN\Administrators" -and $access.FileSystemRights -eq "FullControl") 
            {
                $AdminPerm = $true
                continue
            }
            if ($access.IdentityReference.Value -eq "$Domain\Domain Admins" -and $access.FileSystemRights -eq "FullControl") 
            {
                $DomainAdminPerm = $true
                continue
            }

            Write-Host $filePath.PadRight(15) $access.IdentityReference $access.FileSystemRights 
        }

        if ($SystemPerm -eq $false)
        {
            Write-Host "Missing System Permission to $filePath"
        }

        if ($AdminPerm -eq $false)
        {
            Write-Host "Missing Admin Permission to $filePath"
        }

        if ($DomainAdminPerm -eq $false)
        {
            Write-Host "Missing DominAdmin Permission to $filePath"
        }

        if (($UserPerm -eq $false) -or ($SystemPerm -eq $false) -or ($AdminPerm -eq $false) -or ($DomainAdminPerm = $false))
        {
            return $false
        }
    }
}

Function SetFolderACL([string]$User, [bool]$Recursive, [bool]$EnableInheritance, [bool]$DisableInheritance) 
{  
    $filePath = "$RootFSPath\$User"
    $filePathacl = Get-Acl -Path $filePath

    if ($EnableInheritance -eq $True) #This should not happen if we are looking to disable Inheritance, We want to remove it from the parent folder last below in this code.
    {
        foreach ($access in $filePathacl.Access) 
        {
            #if ($access.IdentityReference.Value -eq $user) {
                #$acl.RemoveAccessRule($access) | Out-Null
                $filePathacl.RemoveAccessRule($access)
            #}
        }

        $filePathacl.SetAccessRuleProtection($false,$false)
        Set-Acl -Path $filePath -AclObject $filePathacl
    }

    if ($Recursive -eq $True)
    {
        $folders = Get-ChildItem $filePath -Recurse #-Directory
        foreach ($folder in $folders) 
        {
            $acl = Get-Acl -Path $folder.FullName

            Write-Host $folder.FullName

            if ($EnableInheritance -eq $True)
            {
                $acl.SetAccessRuleProtection($false,$false)
                Set-Acl -Path $folder.FullName -AclObject $acl
            }
            if ($DisableInheritance -eq $True)
            {
                $acl.SetAccessRuleProtection($true,$true)
                Set-Acl -Path $folder.FullName -AclObject $acl
            }

            foreach ($access in $acl.Access) {
                #if ($access.IdentityReference.Value -eq $user) {
                    #$acl.RemoveAccessRule($access) | Out-Null
                    $acl.RemoveAccessRule($access)
                #}
            }

            Set-Acl -Path $folder.FullName -AclObject $acl

        }
    }

    if ($DisableInheritance -eq $True) #This should not happen if we are looking to disable Inheritance, We want to remove it from the parent folder last below in this code.
    {
        $filePathacl = Get-Acl -Path $filePath   
        $filePathacl.SetAccessRuleProtection($true,$true)

        foreach ($access in $filePathacl.Access) 
        {
            #if ($access.IdentityReference.Value -eq $user) {
                #$acl.RemoveAccessRule($access) | Out-Null
                $filePathacl.RemoveAccessRule($access)
            #}
        }
        Set-Acl -Path $filePath -AclObject $filePathacl
    }

    $acl = Get-Acl -Path $filePath
    $permission = "$Domain\$user", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow"
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
    $acl.SetAccessRule($accessRule)
    $acl | Set-Acl $filepath
} 

Function SetStrightFolderACL([string]$User, [bool]$Recursive, [bool]$EnableInheritance, [bool]$DisableInheritance) 
{
    Write-Host $folder.FullName
    $filePath = "$RootFSPath\$User"
    $filePathacl = Get-Acl -Path $filePath
    $acl = Get-Acl -Path $filePath
    $permission = "$Domain\$user", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow"
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
    $acl.SetAccessRule($accessRule)
    $acl | Set-Acl $filepath 
}

$folders = Get-ChildItem "$RootFSPath" #-Recurse #-Directory
foreach ($folder in $folders) 
{
    $acl = Get-Acl -Path $folder.FullName
    #Write-Host (GetFolderACLRecursive "$RootFSPath\$folder" $folder $false)
    $result = GetFolderACLRecursive "$RootFSPath\$folder" $folder $false
    if ($result -eq $false)
    {
        $Searcher = [ADSISearcher]"(sAMAccountName=$folder)"
        $Results = $Searcher.FindOne()
        If ($Results -eq $Null) 
        {
            #Write-Host "Users does not exist in AD"
        }
        Else 
        {
            #Write-Host "User found in AD"
            SetFolderACL $folder.Name $true $false $True #Remove Inhairtance
            SetFolderACL $folder.Name $true $true $false #Enable Inhairtance
        }        
    }
    #Write-Host $folder.FullName
    #Write-Host $folder.Name
    #GetFolderACL $folder.Name $false
    #SetStrightFolderACL $folder.Name $true $true $false #Enable Inhairtance
    #SetFolderACL $user $true $true $false #Enable Inhairtance
}

exit

#GetFolderACL $user $true
SetFolderACL $user $true $false $True #Remove Inhairtance
SetFolderACL $user $true $true $false #Enable Inhairtance

exit

SetFolderACL $user $true $false $True #Remove Inhairtance

exit

SetFolderACL $user $true $true $false #Enable Inhairtance

exit

Windows Firewall can be a minorly tricky subject when it comes to the configuration at a level with scalability. After connecting with Microsoft it appears the three main options are

1: Group Policy <– Imagine your GPEdit to reflect 1000+ lines of custom configurations for each server in your environment. 2: Desired State Configuration <– Can this be automated easily without a hassle and a lot of technical programming knowledge 3: WMI <– Slow as is everything else in WMI 4: Manual Setup <– ICK! 4: Don’t use it <– Not an option for us

DSC works by generating a MOF file that the client machine read’s to the kick itself into it’s desired state. The client-side digests the file via SMB/HTTP/HTTPS and then ensure’s its configuration is up to date. An interval can be set in the parameters of SetConfiguration but what we really want out of this is can we dynamically generate these .MOF files on the fly to then push to our servers. Let’s take a look at the PowerShell code example and the .MOF it produces to see what it looks like.

You will need a copy of the PowerShell modules below to copy into your Modules folder on your local test machine.

xNetworking

#Unpack xNetworking to the following folders
#C:\Program Files\WindowsPowerShell\Modules
#C:\Program Files (x86)\WindowsPowerShell\Modules
#https://gallery.technet.microsoft.com/scriptcenter/xNetworking-Module-818b3583
Configuration DSCFirewallRule
{
    param
    (
        [string[]] $NodeName = 'localhost'
    )

    Import-DSCResource -ModuleName xNetworking

    Node $NodeName
    {
        xFirewall Firewall1 
        {
            Access      = 'Block'
            Name        = 'NotePadFirewallRule'
            DisplayName = 'Firewall Rule for Notepad.exe'
            Ensure      = 'Present'
            Profile     = ('Domain', 'Private')
            Direction   = 'OutBound'
            RemotePort  = ('8080', '8081')
            LocalPort   = ('9080', '9081')
            Protocol    = 'TCP'
            Description = 'Firewall Rule for Notepad.exe'
            Service = 'WinRM'
        }

        xFirewall Firewall2 
        {
            Access      = 'Allow'
            Name        = 'NotePad++FirewallRule'
            DisplayName = 'Firewall Rule for Notepad++.exe'
            Ensure      = 'Present'
            Profile     = ('Domain', 'Private')
            Direction   = 'OutBound'
            RemotePort  = ('8082', '8084')
            LocalPort   = ('9086', '9085')
            Protocol    = 'TCP'
            Description = 'Firewall Rule for Notepad++.exe'
            Service = 'WinRM'
        }

    }

}

DSCFirewallRule
Start-DscConfiguration -Path .\DSCFirewallRule -Wait -Force -Verbose 

Now, using the code above, it will generate a .MOF file to then use on the destination machines.

/*
@TargetNode='localhost'
@GeneratedBy=Mr. Hall
@GenerationDate=06/12/2018 16:55:22
@GenerationHost=myComputer
*/

instance of MSFT_xFirewall as $MSFT_xFirewall1ref
{
Description = "Firewall Rule for Notepad.exe";
 Direction = "Outbound";
 DisplayName = "Firewall Rule for Notepad.exe";
 ResourceID = "[xFirewall]Firewall1";
 RemotePort = {
    "8080",
    "8081"
};
 Name = "NotePadFirewallRule";
 Ensure = "Present";
 Protocol = "TCP";
 SourceInfo = "C:\\PowerShell\\DSC.ps1::13::9::xFirewall";
 Service = "WinRM";
 LocalPort = {
    "9080",
    "9081"
};
 ModuleVersion = "2.1.1";
 ModuleName = "xNetworking";
 Profile = {
    "Domain",
    "Private"
};
 Access = "Block";

};

instance of MSFT_xFirewall as $MSFT_xFirewall2ref
{
Description = "Firewall Rule for Notepad++.exe";
 Direction = "Outbound";
 DisplayName = "Firewall Rule for Notepad++.exe";
 ResourceID = "[xFirewall]Firewall2";
 RemotePort = {
    "8082",
    "8084"
};
 Name = "NotePad++FirewallRule";
 Ensure = "Present";
 Protocol = "TCP";
 SourceInfo = "C:\\PowerShell\\DSC.ps1::28::9::xFirewall";
 Service = "WinRM";
 LocalPort = {
    "9086",
    "9085"
};
 ModuleVersion = "2.1.1";
 ModuleName = "xNetworking";
 Profile = {
    "Domain",
    "Private"
};
 Access = "Allow";

};

instance of OMI_ConfigurationDocument
{
 Version="1.0.0";
 Author="Mr. Hall";
 GenerationDate="06/12/2018 16:55:22";
 GenerationHost="MyComputer";
};

Now, this is great news. The .MOF file seems predictably easy to regenerate and giving the pattern above, I may be able to write a WebServer to generate out the following pattern and have it pushed to a remote machine, I’ll give it a shot later this week and post the results. Thing’s are looking pretty promising.

Great src on this topic: https://blogs.technet.microsoft.com/heyscriptingguy/2016/01/22/conceptualize-desired-state-configuration-part-5/

So this sniblet is a little something I wrote a few years back that I still use today. In our environment, we have a Public folder that is available to users on the exchange server. Within the Public folder drilling down is a list of Contact cards that are maintained by our secretary. This code will pull that information and apply faces from the HTTPS source matching the employee’s information. In the end, you basically get a nice clean list with employee images attached to see who you are communicating with.

Imports Microsoft.Office.Interop.Outlook
Imports System.Runtime.InteropServices

Public Class Form1

    Private Sub LoadContacts()
        Dim Myresult = MessageBox.Show("Before Running this Program Please clear your local copy of STAFF contacts then press OK", "Are you Ready?", MessageBoxButtons.OKCancel)
        If Not Myresult = vbOK Then End

        Dim oApp = New Microsoft.Office.Interop.Outlook.Application()
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon(Nothing, Nothing, False, True)
        Dim PrivateFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(OlDefaultFolders.olFolderContacts)
        Dim PublicContacts As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(OlDefaultFolders.olPublicFoldersAllPublicFolders).Folders("Staffing").Folders("staff")

        Dim Contacts As Microsoft.Office.Interop.Outlook.MAPIFolder
        Try
            Contacts = PrivateFolder.Folders("staffWpics")
        Catch ex As COMException
            'it does not exist
            Contacts = PublicContacts.CopyTo(PrivateFolder)
            Contacts.Name = "isstaffWpics"
            Debug.WriteLine(Contacts.ShowAsOutlookAB)
            Contacts.ShowAsOutlookAB = True
        End Try

        Dim MyWebRequest As New System.Net.WebClient
        MyWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials

        System.IO.Directory.CreateDirectory("C:\Pics")


        Dim DidIFindPicture As Boolean = False
        For Each MyContact As Microsoft.Office.Interop.Outlook.ContactItem In Contacts.Items
            DidIFindPicture = False
            Dim EID As String
            Dim Email As String
            Try
                MyWebRequest.DownloadFile("https://Faces.Local/EmployeeFace.aspx?FULLNAME=" & MyContact.LastName & ",%20" & MyContact.FirstName, "C:\Pics\" & MyContact.LastName & ",%20" & MyContact.FirstName & ".jpg")
                DidIFindPicture = True
            Catch ex As System.Exception
                Try
                    EID = MyContact.Email1Address.Substring(MyContact.Email1Address.LastIndexOf("=") + 1).PadLeft(5, "0")
                    MyWebRequest.DownloadFile("https://Faces.Local/EmployeeFace.aspx?EID=" & EID, "C:\Pics\" & MyContact.LastName & ",%20" & MyContact.FirstName & ".jpg")
                    DidIFindPicture = True
                Catch exa As System.Exception
                    Try
                        Dim UnCleanedEmail As String = MyContact.Email1DisplayName.Substring(MyContact.Email1DisplayName.LastIndexOf("(") + 1)
                        Email = UnCleanedEmail.Substring(0, UnCleanedEmail.Length - 1)
                        MyWebRequest.DownloadFile("https://Faces.Local/EmployeeFace.aspx?EID=" & Email, "C:\Pics\" & MyContact.LastName & ",%20" & MyContact.FirstName & ".jpg")
                        DidIFindPicture = True
                    Catch exaa As System.Exception
                        Debug.WriteLine("No Picture Found for: " & MyContact.FirstName & " " & MyContact.LastName & " | " & EID & " - " & Email)
                        For Each MyProp As ItemProperty In MyContact.ItemProperties
                            Debug.WriteLine(MyProp.Name & " - " & MyProp.Value.ToString)
                        Next
                    End Try

                End Try
            End Try

            If DidIFindPicture Then
                MyContact.AddPicture("C:\Pics\" & MyContact.LastName & ",%20" & MyContact.FirstName & ".jpg")
                MyContact.Save()
            End If

            For Each Attachment As Microsoft.Office.Interop.Outlook.Attachment In MyContact.Attachments
                Debug.WriteLine(Attachment.DisplayName)
                If Attachment.DisplayName = "ContactPicture.jpg" Then
                    'MyContact.AddPicture("c:\120604_0000.jpg")
                    'MyContact.Save()
                End If
            Next
        Next
        MsgBox("All Pictures Imported as isstaffWpics")
        End
        For Each MyContact As Microsoft.Office.Interop.Outlook.ContactItem In PublicContacts.Items
            'Contacts.Items.Add(
        Next

        End


        For Each MyFolder As Microsoft.Office.Interop.Outlook.MAPIFolder In PrivateFolder.Folders
            Debug.WriteLine(MyFolder.Name)
        Next

        End

        For Each MYContact As Microsoft.Office.Interop.Outlook.ContactItem In PublicContacts.Items
            Debug.WriteLine(MYContact.FirstName)
        Next
        End
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LoadContacts()
    End Sub

    Private Sub Fail()
        Dim oApp = New Microsoft.Office.Interop.Outlook.Application()
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon(Nothing, Nothing, False, True)

        Dim oDLs As Microsoft.Office.Interop.Outlook.AddressLists
        Dim oGal As Microsoft.Office.Interop.Outlook.AddressList

        For Each MyFolder As MAPIFolder In oNS.Folders
            Debug.WriteLine(MyFolder.Name)
            If MyFolder.Name.StartsWith("Public Folders - ") Then
                For Each MySubFolder As MAPIFolder In MyFolder.Folders
                    If MySubFolder.Name = "All Public Folders" Then
                        Debug.WriteLine(MySubFolder.Name)
                        For Each MySubFolder2 As MAPIFolder In MySubFolder.Folders
                            Debug.WriteLine(MySubFolder2.Name)
                            If MySubFolder2.Name = "Information Systems" Then
                                For Each MySubFolder3 As MAPIFolder In MySubFolder2.Folders
                                    If MySubFolder3.Name = "isstaff" Then
                                        Dim outlookname As Microsoft.Office.Interop.Outlook.NameSpace
                                        outlookname = MySubFolder3.Items(0)
                                        Debug.WriteLine(outlookname.AddressLists(0).Name)
                                        oGal = MySubFolder3.Items.Item(0)
                                        Exit Sub
                                    End If
                                Next
                            End If
                        Next
                    End If
                Next
            End If
        Next
        Exit Sub

        For Each AL As Microsoft.Office.Interop.Outlook.AddressList In oDLs
            Debug.WriteLine(AL.Name)
        Next
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Global Address List")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Contacts")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Suggested Contacts")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("staff") 'Right click and show this folder as item in outlook
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Public Folders")

        Dim oEntries As Microsoft.Office.Interop.Outlook.AddressEntries = oGal.AddressEntries
        For Each ADDREntry As Microsoft.Office.Interop.Outlook.AddressEntry In oEntries
            Debug.WriteLine(ADDREntry.Name)

            Dim MyEx = ADDREntry.GetContact
            Debug.WriteLine(MyEx.HasPicture)
            For Each Attachment As Microsoft.Office.Interop.Outlook.Attachment In MyEx.Attachments
                Debug.WriteLine(Attachment.DisplayName)
                If Attachment.DisplayName = "ContactPicture.jpg" Or ADDREntry.Name = "Hall, Nicholas (NickHall@Domain.Com)" Then
                    'Attachment.SaveAsFile("C:\Temp.jpg")
                    PictureBox1.Image = Image.FromFile("C:\Temp.jpg")
                    MyEx.RemovePicture()
                    'MyEx.AddPicture("c:\120604_0000.jpg")
                    MyEx.Save()
                End If
            Next

            If MyEx.Attachments.Count = 0 Then
                'MyEx.AddPicture("c:\120604_0000.jpg")
                'MyEx.Save()
            End If

        Next
    End Sub

    Private Sub GoodCode()
        Dim oApp = New Microsoft.Office.Interop.Outlook.Application()
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon(Nothing, Nothing, False, True)
        Dim oDLs As Microsoft.Office.Interop.Outlook.AddressLists = oNS.AddressLists
        For Each AL As Microsoft.Office.Interop.Outlook.AddressList In oDLs
            Debug.WriteLine(AL.Name)
        Next
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Global Address List")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Contacts")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Suggested Contacts")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("isstaff") 'Right click and show this folder as item in outlook
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Public Folders")
        Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Public Folders\All Public Folders\Staffing")
        Dim oEntries As Microsoft.Office.Interop.Outlook.AddressEntries = oGal.AddressEntries
        For Each ADDREntry As Microsoft.Office.Interop.Outlook.AddressEntry In oEntries
            Debug.WriteLine(ADDREntry.Name)

            Dim MyEx = ADDREntry.GetContact
            Debug.WriteLine(MyEx.HasPicture)
            For Each Attachment As Microsoft.Office.Interop.Outlook.Attachment In MyEx.Attachments
                Debug.WriteLine(Attachment.DisplayName)
                If Attachment.DisplayName = "ContactPicture.jpg" Or ADDREntry.Name = "Hall, Nicholas (NickHall@Domain.Com)" Then
                    'Attachment.SaveAsFile("C:\Temp.jpg")
                    PictureBox1.Image = Image.FromFile("C:\Temp.jpg")
                    MyEx.RemovePicture()
                    'MyEx.AddPicture("c:\120604_0000.jpg")
                    MyEx.Save()
                End If
            Next

            If MyEx.Attachments.Count = 0 Then
                'MyEx.AddPicture("c:\120604_0000.jpg")
                'MyEx.Save()
            End If

        Next


        Exit Sub
        Dim sDL As String = "Information Systems Desktop Support"
        Dim oDL As Microsoft.Office.Interop.Outlook.AddressEntry = oEntries(sDL)
        Dim oEntry As Microsoft.Office.Interop.Outlook.AddressEntry
        Dim I As Integer
        For I = 1 To oEntries.Count - 1
            oEntry = oEntries(I)
            Debug.WriteLine(oEntry.Address)
            Dim MyEx = oEntry.GetExchangeUser
            MyEx.GetPicture()
        Next
    End Sub

    Private Sub WORKS()
        Dim oApp = New Microsoft.Office.Interop.Outlook.Application()
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon(Nothing, Nothing, False, True)
        Dim oDLs As Microsoft.Office.Interop.Outlook.AddressLists = oNS.AddressLists
        For Each AL As Microsoft.Office.Interop.Outlook.AddressList In oDLs
            Debug.WriteLine(AL.Name)
        Next
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Global Address List")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Contacts")
        'Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("Suggested Contacts")
        Dim oGal As Microsoft.Office.Interop.Outlook.AddressList = oDLs("staff") 'Right click and show this folder as item in outlook
        Dim oEntries As Microsoft.Office.Interop.Outlook.AddressEntries = oGal.AddressEntries
        For Each ADDREntry As Microsoft.Office.Interop.Outlook.AddressEntry In oEntries
            Debug.WriteLine(ADDREntry.Name)

            Dim MyEx = ADDREntry.GetContact
            Debug.WriteLine(MyEx.HasPicture)
            For Each Attachment As Microsoft.Office.Interop.Outlook.Attachment In MyEx.Attachments
                Debug.WriteLine(Attachment.DisplayName)
                If Attachment.DisplayName = "ContactPicture.jpg" Then
                    Attachment.SaveAsFile("C:\Temp.jpg")
                    PictureBox1.Image = Image.FromFile("C:\Temp.jpg")
                    MyEx.AddPicture("c:\120604_0000.jpg")
                End If
            Next

        Next

    End Sub
    Private Sub Junk()
        Dim MyContacts As ContactItem
        Dim MyEntry As Microsoft.Office.Interop.Outlook.AddressEntries

        Dim MyMembers As System.Reflection.MemberInfo() = MyContacts.GetType().FindMembers(Reflection.MemberTypes.All, Reflection.BindingFlags.Instance, Nothing, Nothing)
        For Each MyMem As System.Reflection.MemberInfo In MyMembers
            Debug.WriteLine(MyMem.Name)
        Next
    End Sub
End Class

So, In the last few days I am wrapping up some UART code on the esp8266, and as you can tell, it’s been quite a ride. I’ve been working with these Nextion HMI touch screen’s and I gotta say these thing’s are pretty awesome. I love the idea and it’s easy to work with. I’ll post some update’s once I get some program made but so far it’s pretty easy. Now only if I can get this ESP8266 to talk to this thing, everything would be rolling a bit smoother. Anyways to all the other UC / Arudino junkies, Highly recommended. 🙂


//https://www.mikrocontroller.net/attachment/263828/The-ESP8266-Book-August-2015.pdf
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "ip_addr.h"
#include "mem.h"
#include "user_interface.h"
#include "lwip/stats.h"
#include "espconn.h"

#include "c_types.h" ////ONE WIRE

#include "../library/uart.h" //Copy these from your Driver Lib to your local folder
#include "../library/gpio16.h" //Copy these from your Driver Lib to your local folder

#include "../library/common.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1
os_event_t user_procTaskQueue[user_procTaskQueueLen];

void uart0_tx_buffer(uint8 *buf, uint16 len);

char rxbuff[31];
char rxindex = 0;

void UartReceive(char ByteReceived)
{
   os_printf("[%s] Got UART Callback!\r\n", __func__);
   os_printf("Byte Recevied: %c\r\n", ByteReceived);

   rxbuff[rxindex++] = ByteReceived;
   if (rxindex == sizeof(rxbuff)) 
   {
      rxindex = 0;
   }
   else
   {
      os_printf("%d != %d\r\n", rxindex, sizeof(rxbuff));
   }
   os_printf("Buffer: %s\r\n", rxbuff);
}

void ICACHE_FLASH_ATTR sdk_init_done_cb(void) 
{ 
   os_printf("[%s] initializing ESP8266!\n", __func__);
   while(true)
   {
      uart0_tx_buffer("test", 4);
      delay_second();
      delay_second();
   }
}

void ICACHE_FLASH_ATTR user_init()
{
   uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
   //system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart - Makes D7 RX and D8 TX
   system_init_done_cb(sdk_init_done_cb);

   wifi_set_opmode(0);
   wifi_set_sleep_type( NONE_SLEEP_T );

   ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts
   gpio_init();   

   SetAllGPIOPinsAsOutput();

   /* Need to fix this to display value   */
   uint32 VDDADCByte[4] = {0};
   spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF

   os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));
   //Turn off LED
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
   gpio_output_set((1 << 2), 0, 0, 0);

   //Start os task
   system_init_done_cb(sdk_init_done_cb);
   //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
}

LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no, void * callback(uint8))
{
   os_printf("uart_config:%d", uart_no);
   if (uart_no == UART1)
   {
      PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
   }
   else
   {
      /* UART0 */
      ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  callback);
      PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
      PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
      //Enable RxD pin
      //PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U);
      //PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);      
      //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);
   }

   uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));

   if (uart_no == UART1)  
   {
      //UART 1 always 8 N 1
      WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT));
   }
   else
   {  
      //WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(UartDev.data_bits, UartDev.parity, UartDev.stop_bits));
      WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(UartDev.data_bits, NONE_BITS, UartDev.stop_bits)); //Override default settings
   }

   //clear rx and tx fifo,not ready
   SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
   CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);

   //set rx fifo trigger
   //  WRITE_PERI_REG(UART_CONF1(uart_no),
   //                 ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
   //                 ((96 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S) |
   //                 UART_RX_FLOW_EN);
   if (uart_no == UART0)
   {
      //set rx fifo trigger to receive 0x01 byte for each call
      WRITE_PERI_REG(UART_CONF1(uart_no), ((0x01 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | ((0x01 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN | (0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S | UART_RX_TOUT_EN);
      //WRITE_PERI_REG(UART_CONF1(uart_no), ((0x01 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | ((0x01 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN);
      //SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_TOUT_INT_ENA | UART_FRM_ERR_INT_ENA); //This worked
      //Clear pending interrupts
      WRITE_PERI_REG(UART_INT_CLR(UART0), 0xffff);
      //enable rx_interrupt
      SET_PERI_REG_MASK(UART_INT_ENA(UART0), UART_RXFIFO_FULL_INT_ENA);
   }
   else
   {
      WRITE_PERI_REG(UART_CONF1(uart_no), ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));
   }

   //clear all interrupt
   WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
   //enable rx_interrupt
   SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA);
}