Connection to server

Hi, I need my device still working when connection to internet faults, My Conta variable make de intensity of light decrease when there isnt presence and if detect something light turn on automatically, instead there a LDR too, there is a value to compare the amount of light. It still working but the fuction thing.handle() take seconds to try to reconnect and the sensor’s reading are too slows and its not appropriate.
What should I do? Configure the time delay in thing.handle?

   ETWORK] Starting connection...
    [NETWORK] Connecting to network SMARTHINK
    [NETWORK] Cannot connect!
    SensorState:1
    Sensor Luz:297
    Conta:30
    [NETWORK] Starting connection...
    [NETWORK] Connecting to network SMARTHINK
    [NETWORK] Cannot connect!
    SensorState:1
    Sensor Luz:284
    Conta:1
    [NETWORK] Starting connection...
    [NETWORK] Connecting to network SMARTHINK
    [NETWORK] Cannot connect!
    SensorState:0
    Sensor Luz:302
    Conta:1

It may help to see your code
Cheers Matej