logo elektroda
logo elektroda
X
logo elektroda

ESP8266: ThingSpeak and WebServer integration - bugs in the code

Rigardo5033 819 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17997468
    Rigardo5033
    Level 6  
    Hello, I have been playing around with ESP for a while now. I have made a weather station with a PM and temperature sensor. The data is displayed on a web server, and I would like to add a ThingSpeak option, but I can't make sense of it. I have a few questions about this because yes:

    I add these two functions to the ThingSpeak settings
    Code: C / C++
    Log in, to see the code
    .
    Earlier in the program I have to run a web server:
    Code: C / C++
    Log in, to see the code
    .
    I think that this cannot be the case, therefore at api.thingspeak.com I change the name to server1

    Please correct me if I am wrong.

    Then I have a problem with the cliente. Because I use the command for the server:
    Code: C / C++
    Log in, to see the code
    .
    And for ThigSpeak:
    Code: C / C++
    Log in, to see the code
    .
    And it still doesn't send me data to ThingSpeak. Can the client be connected to the web server and the ThingSpeak server at the same time? Or do I have to create a second client?

    Code: C / C++
    Log in, to see the code


    I am a beginner so please understand
  • ADVERTISEMENT
  • #2 17997520
    kaczakat
    Level 34  
    They are two different things, once ESP is serving its server client, once it is a server client, e.g. thinkspeak. When you connect to thikspeak you have to use post or get, I prefer get, e.g.:

    Code: C / C++
    Log in, to see the code
    .
    Same with post:
    Code: C / C++
    Log in, to see the code
    .
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 17997532
    Rigardo5033
    Level 6  
    But if at the beginning of the program I have created
    Code: C / C++
    Log in, to see the code
    .
    And then:
    Code: C / C++
    Log in, to see the code
    .
    This in the function of the one from you:
    Code: C / C++
    Log in, to see the code
    .
    I don't need to give a different name to this client?
  • #5 17997552
    Rigardo5033
    Level 6  
    Super. Only if I already have this client globally created? Won't it clash?
  • ADVERTISEMENT
  • #6 17997610
    kaczakat
    Level 34  
    Compile it and you'll find out, after all the Arduino IDE won't burst laughing in your face. As far as I know it won't bite, the local variable will be used without affecting the global one. But then why do you need a global one?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 17997616
    Rigardo5033
    Level 6  
    To the web server. Here I will use locally. Will test it today I will let you know in the evening. Thank you for your help

    Added after 2 [minutes]: .

    Unfortunately an error:
    Quote:
    'sent' was not declared in this scope
    .
    I don't really know where to declare this and what it is for

    Added after 41 [minutes]:

    I tried the get method. But unfortunately it doesn't work either. I get a response:
    21:13:43.938 -> Cos tam probowano wyslac
    21:13:43.938 -> ESP idzie spac
    
    .
    I don't get the message : Serial.println("Connected to Thinkspeak ");
    So it doesn't connect to the server.
  • #8 18000559
    kaczakat
    Level 34  
    "sent" is some numeric global variable counting the number of attempts to send messages on thinkspeak, just throw it away.
    Here:
    Code: C / C++
    Log in, to see the code
    .
    also appears a global variable, you had your analogue like this.
    If the if doesn't work, it means it didn't connect to the server, you can add an else to the if and print information about it. I actually had the module in a gazebo in the garden and printing that something went wrong was of little importance to me.
    You need to be connected to WIFI, have an IP address assigned, etc. before you can send anything.
    Code: C / C++
    Log in, to see the code
    .

    Similarly, for testing, add an else with a printout that it is not connected to Wifi.
    From the function with "post" remove sleep, in my case it was running on a battery and embracing it is also a separate story.
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around integrating the ESP8266 with ThingSpeak and a web server for a weather station project. The user encounters issues with the code, particularly in managing the WiFiClient instances for both the web server and ThingSpeak. Responses clarify that the ESP8266 can act as both a server and a client, and emphasize the need to use the correct HTTP methods (GET/POST) for communication with ThingSpeak. Suggestions include creating local WiFiClient instances within functions to avoid conflicts with global variables. The user also faces connection issues with ThingSpeak, prompting advice to ensure WiFi connectivity and proper server address usage.
Summary generated by the language model.
ADVERTISEMENT