ESP8266 Web Server POST Requests With JSON Data In Arduino IDE (Mac OSX and Windows)

Поделиться
HTML-код
  • Опубликовано: 2 авг 2024
  • • Your support helps me post videos more frequently:
    / acrobotic
    www.paypal.me/acrobotic
    buymeacoff.ee/acrobotic
    BTC: 1ZpLvgETofMuzCaKoq5XJZKSwe5UNkwLM
    ==========
    • Find me on:
    / acrobotic
    / acrobotic
    / acrobotic
    ==========
    • My shops:
    acrobotic.com/shop
    amazon.com/shops/acrobotic
    ==========
    • Description:
    In this video I show you how to send data to, and process it on, a web server running on the ESP8266. I start with the web server code that was set up in another video ( • ESP8266 Web Server Ste... ), and add a route where to send the data. When the JSON-formatted data is received, it's sent to a callback function, which processes it and extracts the included parameters. The JSON-formatted data specifies the pan and tilt of a servo-powered USB camera mount. I go over the process, step-by-step, of how to write code using the Arduino IDE.
    One of the most common tasks when using the ESP8266 is setting it up as a device that connects to a network and responds to traffic on it (i.e., a web server). I wanted to show you, in detail, how to take things further by using the web server to receive custom data formatted in JSON and included inside of a POST request.
    ==========
    • Project parts:
    ACROBOTIC Development Board for ESP8266:
    acrobotic.com/products/acr-00018
    amzn.to/2dAZ1mW (affiliate)
    ACROBOTIC Pan and Tilt USB Camera Mount:
    acrobotic.com/products/acs-00008
    ==========
    • Project code:
    Firmware for the Arduino IDE:
    github.com/acrobotic/Ai_Tips_...
    Install curl (Mac and Windows):
    curl.haxx.se/download.html
    ==========
    • Tutorials:
    Detailed guide for getting started with the ESP8266 Development Board:
    learn.acrobotic.com/tutorials/...
    ==========
    • Music:
    Jason Shaw (audionautix.com/). Creative Commons License 3.0.
    ==========
    #ESP8266 #Arduino #Tutorial
  • НаукаНаука

Комментарии • 115

  • @briansauerborn5158
    @briansauerborn5158 4 года назад +14

    Hey guys, anyone new coming into this video please note that the ArduinoJson library has updated to version 6. With that, the Parse method has been replaced with a document method.
    New code is as follows:
    String data_string = server.arg("plain");
    StaticJsonDocument jDoc;
    DeserializationError err = deserializeJson(jDoc, data_string);
    JsonObject object = jDoc.as();
    const char* pan = object["pan"];
    const char* tilt = object["tilt"];
    Pan = pan;
    Tilt = tilt;
    At least this is what I have used with success.
    Good luck

    • @datasith
      @datasith  4 года назад +3

      Nice. Thanks for sharing, I switched to version 6 for the latest videos, but these older ones could definitely use an update. I really appreciate posting your solution to get around the incompatibility issues brought by the update!

    • @kalaxbdj8869
      @kalaxbdj8869 4 года назад

      Thanks!

    • @computecastle6099
      @computecastle6099 4 года назад

      Thank you! It was really helpful

    • @AnirudhDua
      @AnirudhDua 4 года назад

      bro can you give me solution firstly it says Pan Tilt not defined and if Serial.print(pan) it gives null like at the serial monitor can you provide the link from which i can learn the version 6 more

  • @carltone
    @carltone 7 лет назад

    I just discovered your video series. I am new to the web side of micro-controllers, your commentary and interactive coding certainly filled in a number of blanks in my quest to understand IOT communication. Very well done thank-you.

    • @datasith
      @datasith  7 лет назад

      Thanks so much for watching, we're glad you are finding the content useful! Plenty more videos are on the way :)

  • @pavankumar-ff9bo8zc5y
    @pavankumar-ff9bo8zc5y 5 лет назад

    What i like most about this channel is that the videos are made simple and very easy to understand. Rather than throwing too many things at us in one go (which is only going to confuse us more and leave us frustrated), the videos are sequenced in a manner that allows us to learn step by step in an incremental fashion making life much easier for a beginner like me. I thoroughly enjoy your videos and wish to see more of them. Thank you!!

    • @datasith
      @datasith  5 лет назад +1

      Thanks for the kind words, Pavan. I'm glad you liked the content!

    • @pavankumar-ff9bo8zc5y
      @pavankumar-ff9bo8zc5y 5 лет назад

      After watching your videos i realised just how much esp8266 is capabale of and i may have barely scratched it’s surface. It really packs a punch. The more you learn the lesser you know. Big things do come in small packages and esp8266 is a living testimony. :)

  • @shsftech3792
    @shsftech3792 3 года назад

    Awesome man! Nicrle tutorial! Thanks.

  • @pepper669
    @pepper669 7 лет назад

    Excellent tutorial! I'm eager to try it out!

    • @datasith
      @datasith  7 лет назад

      Thanks! When you try it out, shoot us an email if you have any questions!

  • @capiberra4118
    @capiberra4118 7 лет назад

    Very useful and well presented. Thanks!

    • @datasith
      @datasith  7 лет назад

      Thanks for watching our videos, Capi!

  • @GuthrieDennis
    @GuthrieDennis 7 лет назад +1

    Awesome tutorial 👍🏽

    • @datasith
      @datasith  6 лет назад

      Thanks for the kind words, we're glad you liked it!

  • @jorgefernandez4812
    @jorgefernandez4812 7 лет назад

    super and helpful video, thnks!

    • @datasith
      @datasith  7 лет назад

      Thanks for watching!

  • @marqueTTronica
    @marqueTTronica 7 лет назад

    Thank you. great video.

    • @datasith
      @datasith  7 лет назад

      Thanks for watching! We're glad you found the vid useful!

  • @lamigrationestunesolution30
    @lamigrationestunesolution30 4 года назад

    thank you so much, very hepful

  • @SenaArnaldo
    @SenaArnaldo 5 лет назад +1

    Great! Grateful! Obrigado!

    • @datasith
      @datasith  5 лет назад

      You're welcome! Por favor!

  • @foreverallama
    @foreverallama 6 лет назад

    Great video. Thanks!

    • @datasith
      @datasith  6 лет назад

      No problem, thanks for watching!

    • @datasith
      @datasith  6 лет назад

      Also, there's no good reason to search for "plain", it's just how the library works :)

    • @foreverallama
      @foreverallama 6 лет назад

      ACROBOTIC Ah I saw your answer for a similar question on an old comment down below so I deleted that part. Thanks anyway :D

  • @quaternion-pi
    @quaternion-pi 7 лет назад

    Another great, clear, helpful tutorial! Thanks! I also would like to see a tutorial where two ESP8266's communicate -MQTT would be an added bonus using an MQTT broker such as a Raspberry Pi.

    • @datasith
      @datasith  7 лет назад

      Glad to have you back as a viewer! :) We'll most definitely be covering those two topics!
      We've got a couple more vids on sending data to the server using your own clients (Python/JavaScript), but then we'll switch it up to requesting data from the ESP8266 from online APIs, as well as other ESP8266s. Fun times ahead!

  • @ph7269
    @ph7269 7 лет назад

    super tutorial..thx

    • @datasith
      @datasith  7 лет назад

      We're glad you liked it, thanks for watching!

  • @abdulsalamfasialshtiway6321
    @abdulsalamfasialshtiway6321 2 года назад

    Thanks for video training
    I have problem in my project I used arduino uno with esp8266 node Mcu to measure two analog PH& Turbidity I check first code of arduino uno in serial I get the result test of 2 sensors how can I program arduino uno and node mcu in that 2 sensors to get result on web will write the program for arduino uno and esp8266 node mcu thanks

  • @Ahmedyashar
    @Ahmedyashar 7 лет назад

    thank you, excellent tutorial.
    could you please do another tutorial for sending the commands from another esp8266?

    • @datasith
      @datasith  7 лет назад

      Thanks for watching, sure thing we'll add it to our queue! :)

  • @jeanchrinot
    @jeanchrinot 3 года назад

    Can we upload the code to Arduino instead of the esp module, and then connect the esp to Arduino board?

  •  7 лет назад

    i have an esp 8266 and a i2c 16,2 lcd, i have made a text box thats suppose to display the user input to lcd screen but i dont know how to grab that user input and put that data inside a variable for displaying on lcd with the lcd command, it sais filenot found on the actual lcd display so im half way there how do i use the posted user data? without using any sd card!

    • @datasith
      @datasith  7 лет назад

      Two words: good luck! :)
      More seriously though, always try to break down your project into smaller pieces. Having problems with displaying data on the LCD? Just focus on that. Print out the variable in question to the Serial Monitor until you see the data you need. Thanks for watching!

  • @nightshade9186
    @nightshade9186 6 лет назад

    can the opposite way be done node mcu sends json to pc with values

    • @datasith
      @datasith  6 лет назад +1

      Night Shade, yes, you can do it in a few ways. The simplest is sending JSON back after receiving a GET request from the PC:
      server.on("/, HTTP_GET,
      server.send(200, "text/json", [](){"{success:true}" );
      });
      The other way is to use the WiFiClient object. The built-in examples are pretty good!
      Thanks for watching!

  • @aliee6
    @aliee6 7 лет назад

    Hi Cisco, you are doing a great job your videos are really beneficial. I was wondering how is it possible to control the servo if the user and ESP8266 both are on different networks?

    • @datasith
      @datasith  7 лет назад +1

      Hi, Mohammad. Thank you for your kind words. The easiest way is to use a service like IFTTT. We'll be making a video this week about this subject. Later on, we'll explain how to do it using your own server instead of a 3rd party. We appreciate having you as a viewer of our videos :)

    • @aliee6
      @aliee6 7 лет назад

      ACROBOTIC : Thanks for writting back, really excited to learn IFTTT for integration. If i have a hosted server some where and want to recieve data(commands) from it through JSON and control servo or any other thing. how this can be done?

    • @datasith
      @datasith  7 лет назад +1

      The gist of it is to program your ESP8266 to periodically ask the server, "should I move the servo", and you should configure the server to respond "no" or "yes, to 125 degrees [for example]". Lastly, your server should have a GUI to facilitate specifying the servo angles. Hope this helps.

  • @denemedeneme6403
    @denemedeneme6403 7 лет назад

    Hello sir, Thank you very much for all your tutorials but i couldn't watch all them yet because lack of time, So i want to ask you a quick question about my graduation project. I hope you can help me :)
    In my project i should use 3 Things, (Raspberry Pi 3 ) as a Server, WeMoS D1R2(will managed by server) so it will "turn on" or "turn off" the light bulb according the server input and Android Phone(I will create an Application to send request to Raspberry Pi 3 Server like "turn on the light in the room 1") and basically i have to create my home server.
    So i tried to create a server on the Raspberry Pi using (ExpressJS and mongoDb) and i made it. But i am not sure how to manage WeMoS using that server and i thought i can create my API and i can provide real-time JSON object to the wemos so it can read the status of the light and according to that value it can do its job as like as below.
    { _id:1,status: 'on', image_url: '/open_light.jpg', redirect_url: 'Close Light',redirect_status: 'off' }
    So my question is, Is there any other good way to mange wemos using raspberry pi 3 server if not then how to parse JSON object from external web server ?, Because my server will run on Raspberry Pi. So i hope you can help me sir :) Thank you very much.

    • @datasith
      @datasith  6 лет назад

      That's not a quick question (and neither is the answer). Good luck with the project :)

  • @manolocapilla3974
    @manolocapilla3974 7 лет назад

    Hi, Im trying to use serial.print to print the data in the JSON but i dont get any data with the arduino. When i enter to the url the function is executed.

    • @datasith
      @datasith  7 лет назад

      Make sure you convert the JSON data to a string! Thanks for watching our videos :)

  • @link_z
    @link_z 6 лет назад

    I'm really happy that I've found your channel. I'm working on a project and I'd like to contact you for some questions, would it be possible? Thanks in advance and keep up the good work!

    • @datasith
      @datasith  6 лет назад +2

      Sorry, it's hard for me to do 1-on-1 chats any more given the size of the community. Best of luck and thanks for stopping by!

    • @link_z
      @link_z 6 лет назад

      Fair enough! Thanks for your fast reply. Do you have any video where I can see how to make my ESP8266 post to a rest API with a JSON body and a header? It'd be great.

    • @datasith
      @datasith  6 лет назад +2

      Yep, for the ESP8266 to send out requests we can use the WiFiClient class. This is an example of using it to send a POST request of JSON-formatted temp/humidity data to a visualization API:
      vid:
      ruclips.net/video/oI5SwqfiB5E/видео.html
      code:
      github.com/acrobotic/Ai_Demos_ESP8266/blob/master/dht_dataviz_ubidots/dht_dataviz_ubidots/dht_dataviz_ubidots.ino
      Thanks for checking out our vids!

    • @link_z
      @link_z 6 лет назад

      ACROBOTIC I managed to do it with your video, I can't be thankful enough!

    • @datasith
      @datasith  6 лет назад +1

      That's awesome! I'm so glad it did, thanks again for watching and also for following up and letting me know :)

  • @HeliosFire9ll
    @HeliosFire9ll 3 года назад

    Hey I've been following your other videos. I got one with a websocket to work. Question is which would have a better response? A websocket or json? I'd like to build a robot car.

    • @datasith
      @datasith  3 года назад

      Heya, thanks for checking out my videos. That's great that you got something working. So websockets is comparable to AJAX, for example. JSON is just how you format the data that's transmitted between devices. I'd go for websockets since they're designed to work as close to real-time as possible. GL!

  • @grankeee
    @grankeee 7 лет назад

    Very nice but for future leave view on code for most of time, please. Only time you have to change view is when you show us reaction of the devices controlled by the program. At any other moment i would like to read and analyze code instead of watching you:P BTW your english sounds pretty clear, one of the few that I am able to understand without focusing too much on understanding

    • @datasith
      @datasith  7 лет назад

      Thanks, we also have the code on the description so that you can have it open and analyze it as we're explaining it (you can even pause the video for extra time). The main reason we don't leave it on for a longer time is so that the video itself doesn't become too long. Thanks for watching!

    • @grankeee
      @grankeee 7 лет назад

      I meant very comfortable for learners on your chanel would be id they can read code, rewrite to their sketch needed parts and listen you in the same time without jumping between pause button, sketch, opened your sketch downloaded from here. At the moment i have to do 'jumping' because whatever you wrote i have not enough time to rewrite at the same time, because immediatly after one line you change view to you body. You don't have to explain me how to manage with this problem, every kid can click pause etc. This is just tip from me (learner of this tutorial who see what can disturb with getting your lesson) to you, what is the thing you can do to improve your guide to actually free of imperfection. As we know removing problems is always better than manage with. Regards :)

  • @navidrct
    @navidrct 4 года назад

    you think , not using colored coding and choosing complex name is cool ?

  • @ezio8000
    @ezio8000 5 лет назад

    I got a message "StaticJsonBuffer not declared in this scope". I had installed ArduinoJson by Benoit Blanchon version 6.7.0-beta. When I changed library to ArduinoJson version 5.13.14. (Sketch > Include Library > Manage libraries, search for Arduino Json) the sketch compiled without any errors. I thought this information might help other users of this video.

    • @datasith
      @datasith  5 лет назад

      Yup, thanks for sharing! I make a point to mention the version in future videos, but it's an issue with older ones. Thanks again!

  • @user-hj1sv7qi4r
    @user-hj1sv7qi4r 5 лет назад

    Great video, is it possible to use just AT commands to Post to a website in JSON format without reprogramming the ESP8266, thanks!

    • @datasith
      @datasith  5 лет назад

      Thanks! Honestly, I don't know what the limitations of AT commands are, though I suspect it should be possible to specify the method of HTTP requests. Sorry I wasn't very helpful.

    • @user-hj1sv7qi4r
      @user-hj1sv7qi4r 5 лет назад

      @@datasith You are very helpful !

  • @JuliusBangert
    @JuliusBangert 7 лет назад

    hi please could you tell me how I would do the same thing but with the esp8266 in access point mode? I eventually aim to make a mobile app that can send json to an esp8266 without the need for a network. Also, how would you store this json permanently on the chip so it can be accessible on a restart?

    • @datasith
      @datasith  7 лет назад

      Anything you put on the firmware will be available on restart! To set it into AP mode, you can use the method:
      WiFi.softAP(ssid, password);
      Thanks so much for watching, good luck with the app!

  • @mohamedziham9378
    @mohamedziham9378 5 лет назад

    Sir, how to call a webapi in esp8266 and post data as json object ?

    • @datasith
      @datasith  4 года назад

      Look at my other videos where I use the WebClient class to do so. Thanks for watching!

  • @sanketbhamre101
    @sanketbhamre101 7 лет назад

    Hi. Very nice tutorial.
    But I did not get --> server.arg("plain") ??
    What does it means? What are other possible values instead "plain"?

    • @datasith
      @datasith  7 лет назад

      It's a simple trick to find the argument we're interested in:
      github.com/esp8266/Arduino/issues/2129
      You can use numbers as indexes. Thanks for watching!

    • @sanketbhamre101
      @sanketbhamre101 6 лет назад

      Thanks :)

  • @waterfallphd8040
    @waterfallphd8040 Год назад

    This code doesnt work for ardujson 6

  • @chiragsehgal6585
    @chiragsehgal6585 7 лет назад

    Hi, can you please help in creating a standalone system ... in which we can control a servo or any appliance from a website .... as esp8266 gets different ip everytime in same or different wifi ... how can we do this globally

    • @datasith
      @datasith  7 лет назад +1

      That would require setting up a server on the internet with which the ESP8266 should communicate. Your requests should be sent to the server, and the ESP8266 should constantly check for new requests on the server. Try watching our Cayenne video for an example on how to do it using a 3rd party service.

    • @chiragsehgal6585
      @chiragsehgal6585 7 лет назад

      Thanx for the valuable reply ... Can you please highlight the topic need to cover to do the same without third party service , so that i can build a independent system.....

  • @sauer.voussoir
    @sauer.voussoir 7 лет назад

    How to add JSON Library to arduino?

    • @datasith
      @datasith  6 лет назад

      As it's shown on this video series.

  • @nachiketacharya2608
    @nachiketacharya2608 5 лет назад

    can we POST command to send images to ESP8266 and the display these on tft

    • @datasith
      @datasith  5 лет назад

      Yup. I trust that you're able to figure out the display part. For uploading have a look at:
      tttapa.github.io/ESP8266/Chap12%20-%20Uploading%20to%20Server.html
      I'm also making a video on a drag-and-drop web interface. Stay tuned!

    • @nachiketacharya2608
      @nachiketacharya2608 5 лет назад

      @@datasith Thanks a lot for the reply:)

  • @rohitsam9311
    @rohitsam9311 7 лет назад

    I want to send the mpu6050 imu sensor's rotation and acceleration values to the webpage.
    Can you help me out?

    • @datasith
      @datasith  7 лет назад

      Certainly! First try an example sketch to get the MPU6050 data and print it to the Serial monitor. Then, use the code in this video: ruclips.net/video/8xqgdXvn3yw/видео.html. Modify it so that instead of using the DHT-22 sensor readings, it uses the MPU6050's!
      HTH

    • @rohitsam9311
      @rohitsam9311 7 лет назад

      yeah thanks!
      I tried as you said and i was able to print it on the serial monitor.
      I want to send the data by sending post requests to a php page on the server.

    • @rohitsam9311
      @rohitsam9311 7 лет назад

      Sorry!
      I didn't get the video you posted.I cannot use the weather url's and location.
      I just want that esp8266 should fetch data from the mpu6050 and send http POST requests to the php page on the server.

    • @datasith
      @datasith  7 лет назад

      On the video we mentioned, the code illustrates how to construct a GET request sent to a server (using *client.print()*). You need to change the code and use it to send a POST request to your PHP page's URL. Inside the request, you'll need to include the data as part of the request. See this example:
      github.com/esp8266/Arduino/issues/1853#issuecomment-249169974
      Another option is to use the HTTPClient object, for which we don't have any examples in our videos yet, but there's quite a few out there!

  • @dazzjh40
    @dazzjh40 7 лет назад

    Good tutorial but doesn't need the disco music

    • @datasith
      @datasith  7 лет назад

      Guess we'll agree to disagree :)

  • @bonny9645
    @bonny9645 5 лет назад

    Can you please add a tutorial to send a json to some other server

    • @datasith
      @datasith  5 лет назад

      Will do! Thanks for watching!

  • @aslamchumroo8571
    @aslamchumroo8571 5 лет назад

    Hi can I use mit app inventor to send the pan tilt data? If so can you please help me how to do it.. Thks

    • @datasith
      @datasith  5 лет назад

      I haven't used App Inventor, but it looks possible. Substitute the URL to your IP address using this example: stackoverflow.com/questions/26572060/app-inventor-2-post

    • @aslamchumroo8571
      @aslamchumroo8571 5 лет назад

      But sir if you want to control the servo from an android phone how are you doing it if you are not using mit app inventor? Is there a better way?

    • @datasith
      @datasith  5 лет назад

      I'm on the side of "whatever works" :)
      Personally, I've used Android Studio to develop simple apps like this one for controlling servos.
      Once you're familiar with App Inventor, I encourage you to try it!

    • @aslamchumroo8571
      @aslamchumroo8571 5 лет назад

      @@datasith OK sir.. Thks a lot for your help :)

  • @Rajat5144
    @Rajat5144 4 года назад

    What will be the URL if we have to do same using Browser
    Well thanks for your project !!

  • @radhakrishnannv5172
    @radhakrishnannv5172 3 года назад

    I didn't know jay z can code

  • @avon9798
    @avon9798 6 лет назад

    JsonObject& jObject = jBuffer.parseObject(data); has a error

    • @datasith
      @datasith  6 лет назад

      Double-check your code, and make sure the ArduinoJson library is installed. Thanks for watching!

    • @avon9798
      @avon9798 6 лет назад

      no the error comes when i code this command specifically

  • @CShand
    @CShand 5 лет назад +1

    why not just use pan = server.arg("pan"); and tilt = server.arg("tilt");

    • @datasith
      @datasith  5 лет назад

      Interesting if it works (I haven't tried your way). When I made this vid you could only get the string passed as a URL parameter by using server.arg("plain"). Things might have changed since then. My logic was that I wanted to use JSON, so the argument is a formatted string that reads {"pan":A_VALUUE,"tilt":ANOTHER_VALUE}. It could pass each value as URL parameters, one called "pan" and another called "tilt", and your suggestion would work. However, JSON is the standard way of passing data so that's why you need the extra code.

    • @CShand
      @CShand 5 лет назад

      @@datasith I see yes I use it when passing data from forms so an input box could have the name "User" and you could then use server.hasarg("User"); to detect it and String value = server.arg("User"); to get it.

    • @datasith
      @datasith  5 лет назад

      Awesome, thanks for sharing. This was definitely not possible a couple of years ago :)

  • @Mike-mo5rh
    @Mike-mo5rh 5 лет назад

    Loud Intro compared to the video! Good Tut otherwise.

    • @datasith
      @datasith  5 лет назад

      Good tut all around, especially the intro!

  • @AmirMotahari
    @AmirMotahari 5 лет назад

    thank you so much, very hepful

    • @datasith
      @datasith  5 лет назад

      You're welcome, thanks so much for watching!