Hi,
Yes, batman-adv gateway is what I am using.
Do I need to write or find a daemon at gateway to sense internet connection, once internet connection is lost (and does not recover within like 2-5 minutes) then advertise batman-adv mesh network by "batctl gw_mode client" to turn this node to be a client?
you can have a mechanism to detect if the uplink connectivity is down and then have the batman-adv gateway switch to client. When the uplink is back, you can switch to gateway mode again.
Depending on how your uplink works, you may not need to write a separate daemon to check (though you can if you want). Most uplink solutions provide some kind of scriptable event for up/down changes. Depends very much on your setup and what you'd like to react to.
Cheers, Marek