top of page

WEEK 9:
Request from Arduino

螢幕截圖 2022-04-05 下午8.41.20.png

TAKEOUTs

Port is the channel to connect to the server. Different port can refer to different services on the same server. For example, 3000 is a service, 2000 is another. 

app.listen(process.env.PORT||8080);

In Glitch, if you console.log the process.env.PORT, it prints a number. In the local server, it is undefined. So, it uses 8080 instead. 

In any kind of online communication, you have yo give out a little identity information, otherwise, the server do not know who to send the response to.

You got an IP address when connected to a network. In a network with PSK (pre-shared keys aka.wifi passwords), the server tend to assign familiar clients the same IP (just like people tend to take the same seat in a classroom). If the conventional IP is taken, the server gives you another one randomly (just like if your old seat is taken, you sit somewhere else). 

Wifi and Server: server is the website you are sending request to, wifi represents through which network you are sending the message. 

ArduinoHttpClient function Documentation:

QUESTIONs

What if using the Glitch server (which prints 3000 for the port number), and the Arduino sends requests to 8080?

The Glitch uses 3000 locally, but for the rest of the world, it uses the global HTTPS port 443. Port 443 is not in plain text, the address you connect to (arduino...glitch/me/) implies this information. When you connect to 443, the Glitch redirects you to 3000. 

Why my response is only printed in the build-in terminal? The visual studio terminal does not print any response?

Different terminal windows are not copies of each other. They are independent. The macOS does not really support running a program in different terminals at the same time. 

How to send the curl request through Arduino? How to represent the -d and -H? (Sample code: HTTPClient-hueBlink)

Curl is a client, just like a browser. However, Arduino does not have a browser, so the Arduino cannot do curl. To send additional elements with a request, Arduino uses request.put. Seems like the function does not do anything with the contentType after defining it. 

 

 

 

 

 

 

 

 

 

Why my public page does not show up?

Because I did not change the lang to the network I am connected to (en0). 

螢幕截圖 2022-04-12 下午7.15.41.png
螢幕截圖 2022-04-12 下午7.21.33.png

request body (curl"")
/api/hueUserName/lights/3/state/

the data (-d)
{"on": false}
{/"on\": false} 

contentType (-H)
application/json

螢幕截圖 2022-04-05 下午8.54.05.png

READINGs

It offers the convenience of web sockets, but without having to maintain a connection to the server, as all communication is message-based, not session-based.

Is that true that MQTT connets to the server only when there is data updates?

bottom of page