B4R Question ESP8266 with DHT11 Not showing Data to Webpage

AndroidMadhu

Active Member
Licensed User
Hello,
I am trying to send DHT11 humid and temp to my test website page. While I am hardcoding the values for humid and temperature it is working fine.
But while I am replacing the hardcode value with the humid and temperature value from dht11, it is not working, instead the value shown in website is text like
-------------
temperature humid
temperature humid
temperature humid
------------
Below is the code snippet:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private MyEsp As ESP8266WiFi
    Private d1pin As D1Pins
    Private D1 As Pin
    Dim humid,temperature As Float
  
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    D1.Initialize(d1pin.D1,D1.MODE_OUTPUT)
    Log("AppStart")
    MyEsp.Connect2("MyWifi","xxxx")
    If MyEsp.IsConnected=True Then
        Log("Router Connected Successfully!!")
    Else
        Log("Failed To connect to Router!!")
        Return
    End If
    RunNative("setup",Null)
    HttpJob.Initialize("Test")
    HttpJob.Download("http://test.com")
End Sub

Sub JobDone(Job As JobResult)
    RunNative("read",Null)
    Delay(2000)
    ''HttpJob.Download("http://test.com/addTemperature.php?temperature=13.7&humidity=45.5")  --->> This is working.
    HttpJob.Download("http://test.com/addTemperature.php?temperature=temperature&humidity=humid") --->> This is not working. Only the text "temperature" and "humid" is coming at the website
    Log("Humid: ",humid) -->this is fine
    Log("Tempa: ",temperature)  -->this is fine
End Sub



#if C
#include "DHT.h"
#define DHTPIN 5  //GPIO5(D1) at ESP8266
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup(B4R::Object* o){
dht.begin();
}
void read (B4R::Object* o) {
   b4r_main::_humid = dht.readHumidity();
   b4r_main::_temperature =dht.readTemperature();
}
#End if

Please advice
 

Attachments

  • Dht11.JPG
    Dht11.JPG
    37.3 KB · Views: 279

AndroidMadhu

Active Member
Licensed User
you should use numberformat.
@janderkan , The numberformat is not working. But your suggestion worked without numberformat.
What I have done is as below :
B4X:
Dim s As String=JoinStrings(Array As String("http://test.com/addTemperature.php?temperature=",temperature,"&humidity=",humid))

It is working. But why the numberformat is not working? As it is required to format the temp or humidity upto 2 decimal.
How Do I achieve this? Please suggest.
 
Upvote 0
Top