I am working with MKR1010, I have connected two heat sensors and created a database to collect the data.
The sketch is working fine and device is getting connected to wifi and posting the data as required.
But this is happening when only connected to USB or a power source. The device is switching ON when connected to batteries but not connecting to WIFI?
That sounds like a hardware problem. Post a schematic of your circuit and how you have it wired, not a frizzy picture. Also include links to technical information on the hardware devices.
If you have while (!Serial); or anything printing to Serial the sketch won't continue on battery power alone because it is waiting for a USB connection. Comment those things out and see if that works.
maybe the cable that connects the batteries to the circuit is not attached ... I say this because it happened to me! ...
otherwise you could disconnect and reattach the batteries once the connection to the PC is removed ...
I have used 4 batteries to power the MKR and it is working fine for a day. After that, it does not send data.
So, This is because of the power issue.
Even though the MKR required only 3.3v , The WIFI needs a 5V or above to start. So, 4.5V supply is enough for the circuit but not wifi.
I have tried low power mode but it is of no use..
Can anyone suggest to draw the power from batteries for a longer period of time?
a tip, if you are using the carrier remove it ... ... otherwise the temperature sensor, (if you do not remove the carrier), it is already there and therefore you do not need to connect 2
however it is normal that it does not last long, you can only push away the moment when it will go out! otherwise you can use a socket connected to the arduino so that it never runs out!
this simple code will let you know both the voltage (with the penultimate line) and the battery percentage (with the last one). The problem is that it changes based on what is being used ... not sure but I think it takes the carrier...
if you need something just ask!
I ran into a similar WiFi problem with a MKR1000. The WiFi could connect fine when on USB power, but would not connect on battery power. It turns out it was an issue with the firmware version and the WINC module. I had to downgrade to a previous version; after which, it worked fine. Here's a Q/A on StackOverflow about it:
I doubt the MKR1010 has the exact same issue since it uses a different communication module, but it would be worth investigating.
For your power issues, I'd recommend going into deepsleep mode, and wakeup/reconnect on regular intervals. This is what I've done for a weather sensor I made. I'm using a 5000mA LiPo battery with a 6V, 300ma solar panel for power. It works better than I expected. I set the wakup interval to 3 minutes. Without charging the battery will last ~10 days, and the solar panel has kept it working for 4 months non-stop.
BTW, disregard the code for reading the battery levels...that part doesn't work when connected to charging power. I'm still trying to figure that part out. Also be aware that when you put the Arduino into deepsleep, it will disable the Serial Monitor. There is a procedure to reinitialize that if you really need it, but I found it to be too much of a hassle (didn't always work) and I didn't need it anyway.