简体   繁体   中英

Arduino Yun not getting response from Azure API

I'm trying to get my Arduino Yun to talk to an API that I'm hosting on Azure. I would like to do more complex things in the future, but at the moment I'm just trying to make a GET request over wifi with a single integer as a parameter.

I'm basically just using the example found here with the url changed. The example works fine, so as far as I'm aware the issue isn't with my board, its with the interaction with Azure.

HttpClient.get() returns an int as a response (not the regular HTTP response codes, its unique for the library). I got 60 initially, and changing my API to accept http calls (instead of just https) fixed this and made me get a response of 0 instead. 0 is the same response that I get from the working Arduino example, but for some reason I'm not actually getting anything in the body of my response, as the client.available() loop is never entered.

The API works as intended when I go to the url in chrome, so the issue arises somewhere due to how the arduino and azure talk to each other, but I don't know enough about either to figure it out and nowhere that I look seems to point me in the right direction.

Any help would be greatly appreciated, thanks.

UPDATE

This question, because I don't have a development board, so I can only give you general advice.

Knowing the premise, there is no problem with the sample interface in the test code, and you also confirm that your azure api can be accessed through chrome normally.

Troubleshooting steps:

  1. Modify the sample code, and print out the returned content in the sample code on the console.

    在此处输入图像描述

Explanation: This step is to confirm whether your development board has normally instantiated HttpClient and whether it has sent http get requests normally.

  1. After the first step is implemented, see if the return value obtained by the development board is still 60. At this time, modify the url and replace the request address of the azure api for testing.

Suggestion: Use a simple test interface that returns string type, such as returning hello world text information, so that you can view the returned data directly on the console.

  1. If the returned value is still 0, it is recommended to turn on application logs at this time and check the log of each request in the portal, so as to ensure whether the development board sends the http request to the azure web app. The log will record the request information and results in detail. Modify the development board code according to the log.

  2. If there is no http request information in the azure logs, or the test sample code did not print the returned content at the beginning, then I guess it may be that the driver of the development board or your product has not been installed and debugged properly. It is recommended to recheck whether the device is normal.

PRIVIOUS

Enable CORS on portal like below.

Add * , then save it to allow all sites.

在此处输入图像描述

Reason:

Via screenshoot, I can see http://127.0.0.1:port want to run, and I believe if it works, it will send http request by HttpClient , so we need to enable cors first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM