If you can't do anything about the hardware you're using (lower powered USB interface, etc) then the top thing you can do is run the wifi radio as little as possible. The radio uses a lot of power, so the less time it's on for and the less network traffic you send, the less power you'll use.
When the board comes out of deep sleep and reconnects on wifi again, it performs a DHCP exchange to find out its IP address. Configuring a static IP address, network mask and router address will avoid this and let the radio stay on for less time.
The ESP8266 SDK also automatically saves wifi credentials to flash every time you call WiFi.begin()
. This is probably not what you want. Disabling this will also help save power.
The new wifi connect code would look something like this:
IPAddress ip( 192, 168, 0, 1 );
IPAddress gateway( 192, 168, 0, 254 );
IPAddress subnet( 255, 255, 255, 0 );
WiFi.forceSleepWake();
delay( 1 );
WiFi.persistent( false );
WiFi.mode( WIFI_STA );
WiFi.config( ip, gateway, subnet );
WiFi.begin( WLAN_SSID, WLAN_PASSWD );
You'd need to replace the specific IP address, gateway (router) address and subnet mask with ones that work for your network. And you'll need to allocate a static IP address either from a range that your router sets aside, or you'll need to configure your router to permanently allocate the address - how you do this totally depends on the router you're using.
The other way to save wifi-related power is to use as lightweight a protocol as possible and do as little work while wifi is on as possible.
For instance, suppose you need to compute a complicated piece of data that you're transmitting over wifi. Maybe it's a chunk of XML or a JSON string. Or you need to read a slow sensor. Do all that work before you enable wifi, and have the data ready to transmit.
Or if you're receiving data, if at all possible, finish receiving the data and turn off wifi before you do any work with the data.
If you have any choice in the matter, use as simple a protocol to transmit the data as possible. UDP is ideal - you can transmit a single packet (but you won't know if it's been received). TCP requires several packets of handshake at connection startup and shutdown. If you use a secure (SSL) connection over TCP that's even more data and computation.
If your very top priority is battery life, UDP is ideal though it's not reliable and not secure.
There's a great series of articles on power saving at
https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-1/
https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-2/
https://www.bakke.online/index.php/2017/05/22/reducing-wifi-power-consumption-on-esp8266-part-3/
Part 1 is about measuring power use; part 2 is about switching the wifi radio on and off and part 3 gets partly into the stuff I talked about above.
nodemcu power consumption deep sleep
in your search engine of choice will show many documented examples of this behaviour