I am trying to acquire rs232 data from a device connected to the ESP8266 (data will then be sent our via http/wifi).

I am using max3232 IC to provide the necessary 3.3v TTL to the ESP8266.

I have have connected the max3232 (pin 12) to GPIO pin 13 (rx) on the ESP8266 (I am only receiving data not sending data, so only the rx pin is connected).

The code i am using:

```
--
--file: test2.lua 
--
tst2 = require "tst2"
tst2.start()

--tst2.lua (testing script)
local module = {}

function module.start()
    print("in tst2.start")
    uart.alt(1)         --use alt GPIO pin 13 (Rx)
    uart.setup(0, 9600,8, uart.PARITY_NONE, uart.STOPBITS_1,0)
    uart.on("data",10, 
        function(data) 
            file.open("data.tmp", "w+")
            file.writeline("starting")
            for i=1,10 do
                 file.writeline(string.byte(string.sub(data,i,i)) )
            end
            file.writeline("from uart: ", data)
            file.writeline("finished")
            file.close()
    end, 0)
    uart.alt(0)         --switch back to standard Rx/Tx pins
end
return module

```

The rs232 device connected to the ESP8266 is putting out a single alphabetic character every 3 seconds, however the data written to file (data.tmp) is as follows

```
starting
10
13
10
13
10
13
10
13
10
13
from uart: 
finished
file.close()

```

Problems:

1- The rs232 device is not issuing any newln or cr characters, but these are appearing in the data file.

2- the string "file.close()" is being written to the data file, and looks like it is the actual lua command that follows the final file.writeline command.

3- the alphabetic data is not appearing in the data file.

4- switching back to the standard uart pins via uart.alt(0) does not work (the ESP8266 must be rebooted - this is not a major issue as the standard uart pins are only used during debugging).

I am writing the rs232 data to a file instead of simply printing it out on the screen (I am using ESPlorer v0.2.0) because the uart.alt(1) command redirects the serial port to the alternative ESP8266 gpio pins. 

I think I am doing something fundamentally wrong with the uart set up, but i can't tell what it is.