Opto-isolator to read 30V with ESP8266 3V3 input
To use an opto-isolator you can use this circuit: 







simulate this circuit &ndash; Schematic created using CircuitLab

The current through R1 is approximately (Vin-1.2V)/R1. Something like 5mA is reasonable for that particular optoisolator and for long life, so for 30V you want something of the order of 5.6K or 4.7K. Power dissipation is less than 200mW so a 1/4-W resistor is fine, but don't use a tiny SMT part without checking. 

R2 is a bit trickier, it depends on safety margin, allowance for aging and the initial CTR (Current Transfer Ratio) for the particular optoisolator bin. If we look at this datasheet, there are four CTR ranks available, and the lowest performance one has a CTR of 50%. So if we assume that is the one, we might allow something like >5:1 for the margin and aging and temperature (higher temperatures are worse) and full saturation, so the current through R2 should be no more than 0.1*5mA = 0.5mA, so with a 3.3V Vdd, that implies 6.6K or more. So 10K should be fine. 

You could choose to use 1mA rather than 5mA and increase both resistors by about 5:1, but that will reduce the speed by a similar factor and put it in the milliseconds range most likely. The CTR is actually guaranteed at 5mA only, but it should follow the relationship in figure 9, from whatever value it is at 5mA. Note that CTR deteriorates more in relative terms at high temperature at 1mA than at 5mA. 

D2 is not necessarily required, but it protects the LED from damage if the voltage can be more negative than  few volts (for example if it is connected incorrectly).