Xinyuan-LilyGO / LilyGo-T-Call-SIM800

https://www.aliexpress.com/item/33045221960.html
471 stars 239 forks source link

When battery powered, will not start if battery bellow ~4V #11

Closed nikil511 closed 5 years ago

nikil511 commented 5 years ago

When T-Call is powered by battery if battery voltage drops bellow ~4V I get brownout errors. (observing serial connected via TX/RX UART not USB)

I am powering the device with multiple 18650 in parallel, so there are enough Amps.

If I start the device with USB or a BAT 4v+, then activate BatteryBoost and then drop bellow 4v it will work without problem. (e.g 3.7V and do GPRS transfers)

However, upon hard reset BattteryBoost goes OFF again. So if I reset with battery bellow 4v ESP32 gets stuck in boot loop with brownout detection error.

Is there a way to store batteryboost enabled permanently on IP5306 ?

crash007 commented 5 years ago

Had the same problem. Activate keep boost on solved it for me. Check the examples. also you can check my closed issue. Good luck

nikil511 commented 5 years ago

Are you talking about issue 8 ? I think what I am describing is different, more complex scenario. I am activating BatteryBoost and I can go bellow 4V if I start with USB and I remove the USB. Also if I start with a +4V battery which eventually drops bellow 4, thats not a problem either.

The problem is that once you are bellow 4V, with BatteryBoost on, No USB, and ...you press reset, then IP5306 BatteryBoost is disabled again, then ESP32 can not start in order to enable BatteryBoost again, so device is stuck in brownout error loop.

The solutions I see are: a) IP5306 reset should not change its values back to default. Is there a permanent "Save" ? b) T-CALL reset button, should not reset IP5306 but only ESP32. This requires hardware modification.

crash007 commented 5 years ago

I did put a 470uF capacitor between 5v and GND but that is not really necessary if you get the boost to work. when i manage to enable boost I could remove the capacitor. My register values is in DEC:

SYS_CTL0: 55 SYS_CTL1: 29 SYS_CTL2: 100

nikil511 commented 5 years ago

it seems I am repeating yours steps :-) I also tried a CAP at 5V with border line success (not stable) I also found out I was working on a dodgy module that was more sensitive.

So for enabling boost I was using code from the M5STACK power class and the example from @vshymanskyy

However I have not tampered with CTL1 & CTL2 yet Thanks for the tip! I will be back shortly :-)

nikil511 commented 5 years ago

Problem persists. I am trying on 4 different modules, (two of them have a proper 5V line) I set the registers first thing in setup. If I remove USB everything works fine with battery at 3.7V If I press reset, it boots normally, executes the set registers part but as soon as it tries to turn on the SY8089 4v4 regulator for SIM800 (MODEM_POWER_ON set High) it gets a brownout error.

I know that PowerBoost works, because if I turn it off, then it will not reach that far! It crashes immediately upon reset/boot. With PowerBoost ON the ESP32 works fine, its only when SIM800 gets activated that it fails with brownout.

@crash007 Have you tried resetting with a low bat AND a firmware that is using GSM ?

nikil511 commented 5 years ago

ok, I have answers.

1 unit does not work reliably (brownout / guru meditation /etc) with battery no mater what the voltage! Addition of capacitor made things better but not good enough.

2 units work ok up to ~4V. When I added capacitors AND replaced the thin cable of the tiny plug, they can reach 3.3v on battery without problem

1 unit works up to 3.3v without having to add capacitor or replacing plug cable.

So thats 1/4 for reliability :-(

On all units, the 5V line is 4.5V when powered via USB and 5V when running on battery. I am guessing with a low quality USB-C cable, there might power problems when SIM800 is working.

However @crash007 your registers do indeed fix the problem with power boost ( if the hardware is not messed up )

crash007 commented 5 years ago

I have been monitoring my vcc and now when the battery has droped below 4v it doesnt upload any more. @nikil511

nikil511 commented 5 years ago

So @crash007 you confirm my findings, and it's not just a matter of I2C IP5306 settings. @lewisxhe @vshymanskyy you need to increase the capacitor at 5V or 4V4 for the GSM to work on battery. Please see #13

crash007 commented 5 years ago

Yes I can confirm your findings. I have monitored the vcc and when i get below 4v it stops to transmitt messages.

Den tors 22 aug. 2019 kl 14:20 skrev Manolis Nikiforakis < notifications@github.com>:

So @crash007 https://github.com/crash007 you confirm my findings, and it's not just a matter of I2C SY8089 settings. @lewisxhe https://github.com/lewisxhe @vshymanskyy https://github.com/vshymanskyy you need to increase capacitor at 5V or 4V vbus for the GSM to work on battery. Please see #13 https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/13

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=ACWEUMZXJDT3HK7EUXOXHWLQF2AAFA5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD444W5I#issuecomment-523881333, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWEUM2BTIDHIZD46HIKKJ3QF2AAFANCNFSM4IJBXUDA .

imranaalam commented 4 years ago

@nikil511 i am facing the same problem. what is " thin cable of the tiny plug" ; can you please attach the picture? any more insights since last time? have you tried some other solutions other than ttgo-call? ESP32 + sim800l?

nikil511 commented 4 years ago

I have tried many combinations of ESP32 with some external gsm module. Problem is that are all prone to noise on the tx/rx thus an all in one board is better.

Thin cable issue: i have noticed instability problems (brownout) when powered by the included battery cable and one 18650 not fully charged. When i skipped that cable and plug and powered tcall directly with a soldered thicker cable, added capacitor on 5v, those problems went away and tcall was working with battery at 3v.

Thus I conclude that the combination of battery cable, plug and capacitors on tcall are not suitable for the 2A gsm spikes, and ideally all three need to change to be on the safe side and allow operation with empty batteries.

On Thu, Nov 28, 2019, 22:03 imranaalam notifications@github.com wrote:

@nikil511 https://github.com/nikil511 i am facing the same problem. what is " thin cable of the tiny plug" ; can you please attach the picture? any more insights since last time? have you tried some other solutions other than ttgo-call? ESP32 + sim800l?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=AAHB4OWTZKHMQLGKO2TDIQDQWAPY3A5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFNLXVY#issuecomment-559594455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4ORQDRSTABIQGRG4NKDQWAPY3ANCNFSM4IJBXUDA .

RamiRihawi commented 4 years ago

@nikil511 I have the same issue where TTGo-Tcall is not running from battery not even if the battery is above 4v. it shows the same symptoms where running it from USB works fine, and removing the USB mid way while connected to battery works as expected, but once the ESP is reset i face the brownout loop issue.

I even tried to connect the battery pins directly to DC power supply and set the latest to 4.1V same issue. it seems that the module can only be powered from the USB port.

P.S. i tried the same methods on two different modules, both bought from Bangood. the two behave exactly the same.

1- When you mentioned adding Capacitors, where exactly did you add them. To the raw of Capacitors connected to the sim module 5v rail from the booster IC? (adding more capacitors to the 3 capacitors delivering the boosted 5V)?

2- have you tried to change the aforementioned capacitors to maybe better quality ones?

any other tips based on the tests i've done already?

nikil511 commented 4 years ago

You need to enable the IP5306 boost, over I2C. Have a look at the example code. Capacitor is needed for using GSM at low voltage. You connect it at 5v and GND pins.

On Sun, Dec 1, 2019, 11:51 RamiRihawi notifications@github.com wrote:

@nikil511 https://github.com/nikil511 I have the same issue where TTGo-Tcall is not running from battery not even if the battery is above 4v. it shows the same symptoms where running it from USB works fine, and removing the USB mid way while connected to battery works as expected, but once the ESP is reset i face the brownout loop issue.

I even tried to connect the battery pins directly to DC power supply and set the latest to 4.1V same issue. it seems that the module can only be powered from the USB port.

P.S. i tried the same methods on two different modules, both bought from Bangood. the two behave exactly the same.

1- When you mentioned adding Capacitors, where exactly did you add them. To the raw of Capacitors connected to the sim module 5v rail from the booster IC? (adding more capacitors to the 3 capacitors delivering the boosted 5V)?

2- have you tried to change the aforementioned capacitors to maybe better quality ones?

any other tips based on the tests i've done already?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=AAHB4OV7FHQ57WDLZIPFGYLQWOCIPA5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRDKVQ#issuecomment-560084310, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OXHWCHUJEW4BK72KBTQWOCIPANCNFSM4IJBXUDA .

kabukimandelux commented 4 years ago

Had the same issue, thanks for the suggestion with the 470uF capacitor. Seems to work fine now! Wired to 5v pin and ground

jbrepogmailcom commented 4 years ago

Dear @nikil511 Manolis, seems that you are very experienced with battery optimization and you know most of all other people. I also had problem with thin wires, so I connected LiPo battery directly to 5V rail, but it is still shutting down when under 4V.

I think it would help many other people - can I please ask you to write short howto, how to optimize the module for GSM battery use? Like 1) use thick wires connected directly to 5V, 2) use capacitor, 3) use library for BatteryBoost... Especially I am not clear how to use the battery boost, if it has to be enabled at each start, or can be activated through some registers or wiring... I also guess that many of us use wakeup from sleep by interrupt from sensor - is that approach compatible with batteryboost?

I also have read that the IP5306 has quiescent current of 100uA, so I would be curious if the chip can be turned off when the module sleeps. When I think of it, the sequence would be like this: turn off SIM8000L part - turn off BatteryBoost module - ESP32 sleep - wakeup by interrupt or timer - turn on BatteryBoost - turn on SIM800L. Would that work?

Thank you very much for your kindness, Jan

nikil511 commented 4 years ago

Have you tried the tinygsm example? https://github.com/Xinyuan-LilyGO/TTGO-T-Call/tree/master/examples/Arduino_TinyGSM

it contains the batteryboost part and should work with battery + better cables + capacitor at 5V Wake from interrupt is irrelevant to IP5306, so will work.

I will tideup my repo and publish examples in the future, but here are the important registers of the IP5306 and what they do based on my research. My goal was to somehow make the system wake up after power failure. Apparently that is not possible, reset has to be pressed. To make things worst bellow 3V IP5306 enters a zombie mode where it consumes 50mA without powering the rest of the board, thus a non-protected lithium battery will go down to zero (!)

define IP5306_ADDR 0x75

define IP5306_REG_SYS_CTL0 0x00

define IP5306_REG_SYS_CTL1 0x01

Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); Wire.write(0b110111); // 0x37 = 0b110111 TCALL example / [1] Boost EN (default 1) [EXM note: if 0 ESP32 will not boot from battery] [1] Charger EN (1) [EXM note: did not observe difference] [1] Reserved (1) [EXM note: did not observe difference] [1] Insert load auto power EN (1) [EXM note: did not observe difference] [1] BOOST output normally open ( 1) [EXM note: if 0 will shutdown when ESP32 sleeps after 32s] [1] Key off EN: (0) [EXM note: could not detect difference] / Wire.write(IP5306_REG_SYS_CTL1); Wire.write(0x1D); // Set HEX:1D DEC:29 BIN:11101 / [1] Turn off boost control signal selection: short press twice [1] Switch WLED flashlight control signal selection: short press twice [1] Short press switch boost: disabled [0] Whether to turn on Boost after VIN is pulled out: opened [1] Batlow 3.0V Low Power Shutdown EN: enabled /

On Tue, Jan 21, 2020 at 2:45 PM jbrepogmailcom notifications@github.com wrote:

Dear @nikil511 https://github.com/nikil511 Manolis, seems that you are very experienced with battery optimization and you know most of all other people. I also had problem with thin wires, so I connected LiPo battery directly to 5V rail, but it is still shutting down when under 4V.

I think it would help many other people - can I please ask you to write short howto, how to optimize the module for GSM battery use? Like 1) use thick wires connected directly to 5V, 2) use capacitor, 3) use library for BatteryBoost... Especially I am not clear how to use the battery boost, if it has to be enabled at each start, or can be activated through some registers or wiring... I also guess that many of us use wakeup from sleep by interrupt from sensor - is that approach compatible with batteryboost?

Thank you very much for your kindness, Jan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=AAHB4OSTHZ7GXDJBL23BKGLQ63U73A5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJPTNHA#issuecomment-576665244, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OVE3O3ZC3ZPVYYV6UTQ63U73ANCNFSM4IJBXUDA .

jbrepogmailcom commented 4 years ago

I see, thanks. I took some different approach from elsewhere, but I have no idea if it works. Maybe I should connect battery back to VBAT and not to +5V, as I had until now (I realized I was bypassing IP5306). But I think VBAT connector is too bad it did not work for SIM800L..

// I2C for SIM800 (to keep it running when powered from battery) TwoWire I2CPower = TwoWire(0);

define IP5306_ADDR 0x75

define IP5306_REG_SYS_CTL0 0x00

bool setPowerBoostKeepOn(int en){ I2CPower.beginTransmission(IP5306_ADDR); I2CPower.write(IP5306_REG_SYS_CTL0); if (en) { I2CPower.write(0x37); // Set bit1: 1 enable 0 disable boost keep on } else { I2CPower.write(0x35); // 0x37 is default reg value } return I2CPower.endTransmission() == 0; }

nikil511 commented 4 years ago

You can bypass ip5306 and all problems related to it, by providing 5v to the 5v line using an external step up (eg lipo rider)

But putting a battery (3-4v) to the 5v is not a long term solution :-)

On Tue, Jan 21, 2020, 21:01 jbrepogmailcom notifications@github.com wrote:

I see, thanks. I took some different approach from elsewhere, but I have no idea if it works. Maybe I should connect battery back to VBAT and not to +5V, as I had until now (I realized I was bypassing IP5306). But I think VBAT connector is too bat it did not work for SIM800L..

// I2C for SIM800 (to keep it running when powered from battery) TwoWire I2CPower = TwoWire(0);

define IP5306_ADDR 0x75

define IP5306_REG_SYS_CTL0 0x00

bool setPowerBoostKeepOn(int en){ I2CPower.beginTransmission(IP5306_ADDR); I2CPower.write(IP5306_REG_SYS_CTL0); if (en) { I2CPower.write(0x37); // Set bit1: 1 enable 0 disable boost keep on } else { I2CPower.write(0x35); // 0x37 is default reg value } return I2CPower.endTransmission() == 0; }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=AAHB4OSUBRYT4C646TJIGI3Q65BBRA5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJQ3SSQ#issuecomment-576829770, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OQ4RHGWTZF4G2GN7ZTQ65BBRANCNFSM4IJBXUDA .

schmeckm commented 4 years ago

Hi Nikil you have mentioned that you can boot the Board directly over 5 V Line. I checked the Pinout of the Board, but I can not see a "VIN" to connect a Lipo rider? What kind of Pin are you using as a Input? Markus

nikil511 commented 4 years ago

Pin "5V" :-)

On Fri, Jan 31, 2020, 13:57 schmeckm notifications@github.com wrote:

Hi Nikil you have mentioned that you can boot the Board directly over 5 V Line. I checked the Pinout of the Board, but I can not see a "VIN" to connect a Lipo rider? What kind of Pin are you using as a Input? Markus

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/TTGO-T-Call/issues/11?email_source=notifications&email_token=AAHB4OVHQT4XA6GWMJTA633RAQG4HA5CNFSM4IJBXUDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKONY2Q#issuecomment-580705386, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OWNYDCCZSGEBGDZVGLRAQG4HANCNFSM4IJBXUDA .

schmeckm commented 4 years ago

Ok its strange if I connect the Board to the USB than I get 5 Volt out. I was not aware of it that I can also connect this 5 Volt Pin with a external Power Supply.

Markus

vitalstates commented 4 years ago

hello I'm new here, just feeling my way around....hoping this thread is still alive...

I'm looking for info on how to run the board without a battery and have drawn a blank on any background documentation.

I am replacing a uno with sim900 in a remote location so it will have a 12v battery maintained by solar panel. At present I just use standard regulators to power the uno and gprs.

I'm hoping to be able to use the ttgo board powered from the usb(pc) with ancilliary power for the sim800 whilst programming and debugging connected to the pc. This without any of the battery and associated charging stuff.

HuxleyFred commented 3 years ago

Hi, just a comment with respect to the example code above - specifically:

if (en) { I2CPower.write(0x37); // Set bit1: 1 enable 0 disable boost keep on } else { I2CPower.write(0x35); // 0x37 is default reg value }

If you look at the data sheet (unfortunately written in Chinese), then it indicates that these registers contain reserved fields that should be maintained when updating them. So you should use a read-modify-write sequence to change them. i.e. if you wish to just set the two 'boost' related bits you should first read this control register, OR in 0x22 and then write it rather than just writing 'magic numbers'.

See: https://github.com/m5stack/M5-Schematic/blob/master/Core/IIC_IP5306_REG_V1.4.pdf

bhupiister commented 3 years ago

@nikil511 if you are still active on this thread @lewisxhe if you can help on this. I have removed the battery plug on back and soldered the thick wire directly on board. I am facing issue of board consuming 50mA current when I try to power the board on battery. However, Once I press reset and it enters sleep mode, it consumes 1-2mA. I have also attached 450uF capacitor between 5v and GND. I just need a way of avoiding 50mA current if the board resets accidentally on battery.

nikil511 commented 3 years ago

Tcall has 3 versions with different power management circuit. If you are taking about 1st version, battery has to stay connected and above 3v else reset has to be pressed.

I remember the 50ma problem you mention, it's a zombie mode when the ip5306 is not properly initialized.

If you want to use it in unattended setup, with unstable power, (eg battery

On Tue, Jan 26, 2021, 06:40 bhupiister notifications@github.com wrote:

@nikil511 https://github.com/nikil511 if you are still active on this thread @lewisxhe https://github.com/lewisxhe if you can help on this. I have removed the battery plug on back and soldered the thick wire directly on board. I am facing issue of board consuming 50mA current when I try to power the board on battery. However, Once I press reset and it enters sleep mode, it consumes 1-2mA. I have also attached 450uF capacitor between 5v and GND. I just need a way of avoiding 50mA current if the board resets accidentally on battery.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/LilyGo-T-Call-SIM800/issues/11#issuecomment-767291723, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OVMMP66EIMZYTMROK3S3ZBSPANCNFSM4IJBXUDA .

bhupiister commented 3 years ago

@nikil511 can I power it via 3.3 V on 3v3 and GND pin? I am ordering TP4056 with LDO to regulate output at 3.3 volt with capacitors to surpress spikes if any. Will this give also generate 5v via onboard registers?

bhupiister commented 3 years ago

@nikil511 I am using version with ip5306 ,2019 version.

nikil511 commented 3 years ago

I have not used the latest version, but 5v has to exist, as another regulator makes 4v for gsm and 3v for esp32.

On Tue, Jan 26, 2021, 19:18 bhupiister notifications@github.com wrote:

@nikil511 https://github.com/nikil511 I am using version with ip5306 ,2019 version.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Xinyuan-LilyGO/LilyGo-T-Call-SIM800/issues/11#issuecomment-767694979, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHB4OQMFWMHRHDWGWK4J4TS332OVANCNFSM4IJBXUDA .

kekko7072 commented 2 years ago

I am thing to connect a 3.7 V 2000mAh Lipo battery to the battery pin but when I connect it says

Brownout detector was triggered
11:13:20.243 -> 
11:13:20.243 -> ets Jun  8 2016 00:22:57
11:13:20.243 -> 
11:13:20.243 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT   ets Jun  8 2016 00:22:57
11:13:20.484 -> 
11:13:20.484 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
11:13:20.484 -> configsip: 0, SPIWP:0xee
11:13:20.484 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
11:13:20.484 -> mode:DIO, clock div:1
11:13:20.518 -> load:0x3fff0018,len:4
11:13:20.518 -> load:0x3fff001c,len:1216
11:13:20.518 -> ho 0 tail 12 room 4
11:13:20.518 -> load:0x40078000,len:10944
11:13:20.518 -> load:0x40080400,len:6388
11:13:20.518 -> entry 0x400806b4

This is the port IMG_0338

This is the battery IMG_0339 copia

What battery should I use to make it work using the battery?

GyTe commented 8 months ago

Hopefully this will help someone in my same situation. I've find out a "solution" merging information from here and outside. At least for me I been able to power from a solar panel (standard 6 volt - 2 watt) a Lilygo T-Call Sim800L (hardware revision 20190610 - IP3506) using a TP4056 charging module (the revision that accept usb-c as input)

Basically I've connected the solar panel to TP4056 Input, a 18650 to battery (to store energy) and output of TP4056 to the battery connector of Lilygo. Then I put a capacitor on 5 volt (as per above suggestion).

The first start need to be done pressing the reset button but at least for now (1 month on the roof) everything seems to be ok. My use for now is to retrieve temperature / humidity and battery voltage, post on Thingspeak and then deepsleep for 1 hour.

To have everything in the same place and in order to avoid rain / humidity ecc I've put everything inside a box used for electric junction. I did just a little hole for the BME280 sensor (in order to pick-up external temperature) and another hole to use external GSM antenna.

I'm quite sure there're some other "elegant" solution and I'm quite sure the battery life can't run forever (hot and cold weather do not help) but at least for now I'm happy of the result.

For now I'll leave the box on my roof, then when I'm sure that everything is fine, I'll replace the battery with a brand new, charge with external power supply and then travel to a remote location where I need to pick-up that information (more or less 50km far from my home).

Hope this help and thanks to everybody for the suggestion.

P.S. In case battery will discharge completely and solar panel will be enough to charge it again, as you know, the Lilygo wont power-up automatically again but honestly I don't have the knowledge to fix that.... as per now everything will run as per above setup.

ridwanmullick commented 6 months ago

nothing worked but the settings and configurations of this code seems to be working

/* Rui Santos Complete project details at https://RandomNerdTutorials.com/esp32-sim800l-publish-data-to-cloud/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */

// Your GPRS credentials (leave empty, if not needed) const char apn[] = ""; // APN (example: internet.vodafone.pt) use https://wiki.apnchanger.org const char gprsUser[] = ""; // GPRS User const char gprsPass[] = ""; // GPRS Password

// SIM card PIN (leave empty, if not defined) const char simPIN[] = "";

// Server details // The server variable can be just a domain name or it can have a subdomain. It depends on the service you are using const char server[] = "example.com"; // domain name: example.com, maker.ifttt.com, etc const char resource[] = "/post-data.php"; // resource path, for example: /post-data.php const int port = 80; // server port number

// Keep this API Key value to be compatible with the PHP code provided in the project page. // If you change the apiKeyValue value, the PHP file /post-data.php also needs to have the same key String apiKeyValue = "tPmAT5Ab3j7F9";

// TTGO T-Call pins

define MODEM_RST 5

define MODEM_PWKEY 4

define MODEM_POWER_ON 23

define MODEM_TX 27

define MODEM_RX 26

define I2C_SDA 21

define I2C_SCL 22

// BME280 pins

define I2C_SDA_2 18

define I2C_SCL_2 19

// Set serial for debug console (to Serial Monitor, default speed 115200)

define SerialMon Serial

// Set serial for AT commands (to SIM800 module)

define SerialAT Serial1

// Configure TinyGSM library

define TINY_GSM_MODEM_SIM800 // Modem is SIM800

define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

// Define the serial console for debug prints, if needed //#define DUMP_AT_COMMANDS

include

include

ifdef DUMP_AT_COMMANDS

include

StreamDebugger debugger(SerialAT, SerialMon); TinyGsm modem(debugger);

else

TinyGsm modem(SerialAT);

endif

include

include

// I2C for SIM800 (to keep it running when powered from battery) TwoWire I2CPower = TwoWire(0);

// I2C for BME280 sensor TwoWire I2CBME = TwoWire(1); Adafruit_BME280 bme;

// TinyGSM Client for Internet connection TinyGsmClient client(modem);

define uS_TO_S_FACTOR 1000000UL / Conversion factor for micro seconds to seconds /

define TIME_TO_SLEEP 3600 / Time ESP32 will go to sleep (in seconds) 3600 seconds = 1 hour /

define IP5306_ADDR 0x75

define IP5306_REG_SYS_CTL0 0x00

bool setPowerBoostKeepOn(int en){ I2CPower.beginTransmission(IP5306_ADDR); I2CPower.write(IP5306_REG_SYS_CTL0); if (en) { I2CPower.write(0x37); // Set bit1: 1 enable 0 disable boost keep on } else { I2CPower.write(0x35); // 0x37 is default reg value } return I2CPower.endTransmission() == 0; }

void setup() { // Set serial monitor debugging window baud rate to 115200 SerialMon.begin(115200);

// Start I2C communication I2CPower.begin(I2C_SDA, I2C_SCL, 400000); I2CBME.begin(I2C_SDA_2, I2C_SCL_2, 400000);

// Keep power when running from battery bool isOk = setPowerBoostKeepOn(1); SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));

// Set modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); pinMode(MODEM_RST, OUTPUT); pinMode(MODEM_POWER_ON, OUTPUT); digitalWrite(MODEM_PWKEY, LOW); digitalWrite(MODEM_RST, HIGH); digitalWrite(MODEM_POWER_ON, HIGH);

// Set GSM module baud rate and UART pins SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX); delay(3000);

// Restart SIM800 module, it takes quite some time // To skip it, call init() instead of restart() SerialMon.println("Initializing modem..."); modem.restart(); // use modem.init() if you don't need the complete restart

// Unlock your SIM card with a PIN if needed if (strlen(simPIN) && modem.getSimStatus() != 3 ) { modem.simUnlock(simPIN); }

// You might need to change the BME280 I2C address, in our case it's 0x76 if (!bme.begin(0x76, &I2CBME)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); }

// Configure the wake up source as timer wake up
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); }

void loop() { SerialMon.print("Connecting to APN: "); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { SerialMon.println(" fail"); } else { SerialMon.println(" OK");

SerialMon.print("Connecting to ");
SerialMon.print(server);
if (!client.connect(server, port)) {
  SerialMon.println(" fail");
}
else {
  SerialMon.println(" OK");

  // Making an HTTP POST request
  SerialMon.println("Performing HTTP POST request...");
  // Prepare your HTTP POST request data (Temperature in Celsius degrees)
  String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(bme.readTemperature())
                         + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
  // Prepare your HTTP POST request data (Temperature in Fahrenheit degrees)
  //String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(1.8 * bme.readTemperature() + 32)
  //                       + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";

  // You can comment the httpRequestData variable above
  // then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
  //String httpRequestData = "api_key=tPmAT5Ab3j7F9&value1=24.75&value2=49.54&value3=1005.14";

  client.print(String("POST ") + resource + " HTTP/1.1\r\n");
  client.print(String("Host: ") + server + "\r\n");
  client.println("Connection: close");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.print("Content-Length: ");
  client.println(httpRequestData.length());
  client.println();
  client.println(httpRequestData);

  unsigned long timeout = millis();
  while (client.connected() && millis() - timeout < 10000L) {
    // Print available data (HTTP response from server)
    while (client.available()) {
      char c = client.read();
      SerialMon.print(c);
      timeout = millis();
    }
  }
  SerialMon.println();

  // Close client and disconnect
  client.stop();
  SerialMon.println(F("Server disconnected"));
  modem.gprsDisconnect();
  SerialMon.println(F("GPRS disconnected"));
}

} // Put ESP32 into deep sleep mode (with timer wake up) esp_deep_sleep_start(); } Screenshot 2024-03-12 124328