http-web-request-get

Migrate from
https://cmakerhk.wordpress.com/2018/10/03/processing-web-request/


include the library by searching runemadsen

Sample code:

//Processing Code
import http.requests.*;

GetRequest get = new GetRequest("https://httpbin.org/ip");
get.send();
println("Reponse Content: " + get.getContent());
println("Reponse Content-Length Header: " + get.getHeader("Content-Length"));

result:

Reponse Content: {
  "origin": "203.85.99.9"
}

Reponse Content-Length Header: 30

Sample code2:

/**
 * HTTP Client. 
 * 
 * Starts a network client that connects to a server on port 80,
 * sends an HTTP 1.0 GET request, and prints the results. 
 *
 * Note that this code is not necessary for simple HTTP GET request:
 * Simply calling loadStrings("http://www.processing.org") would do
 * the same thing as (and more efficiently than) this example.
 * This example is for people who might want to do something more 
 * complicated later.
 */


import processing.net.*;

Client c;
String data;

void setup() {
  size(200, 200);
  background(50);
  fill(200);
  c = new Client(this, "httpbin.org", 80); // Connect to server on port 80
  c.write("GET /ip HTTP/1.0\r\n"); // Use the HTTP "GET" command to ask for a Web page
  c.write("Host: httpbin.org\r\n");
  c.write("\r\n");
}

void draw() {
  if (c.available() > 0) { // If there's incoming data from the client...
    data = c.readString(); // ...then grab it and print it
    println(data);
  }
}

result:

Client got end-of-stream.
HTTP/1.1 200 OK
Connection: close
Server: gunicorn/19.9.0
Date: Wed, 03 Oct 2018 07:01:44 GMT
Content-Type: application/json
Content-Length: 30
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Via: 1.1 vegur

{
  "origin": "203.85.99.9"
}


//linux code

curl -X GET "http://httpbin.org/get" -H "accept: application/json"

return:

{
  "origin": "203.85.99.9"
}

httpie:


WEB request full statement

GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
    1. A Request-line
    2. Zero or more header (General|Request|Entity) fields followed by CRLF
    3. An empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields
    4. Optionally a message-body
Request-Line = Method SP Request-URI SP HTTP-Version CRLF
Request-URI = "*" | absoluteURI | abs_path | authority

ref:: https://www.tutorialspoint.com/http/http_requests.htm

introduction-to-firmata

Migrate from https://cmakerhk.wordpress.com/2018/10/02/firmata/


Firmata:是一種通訊協定(protocol),是一種用於微控制器與電腦中軟體間的協助通訊的通訊協定。

https://github.com/firmata/arduino

Tools for testing
https://github.com/firmata/firmata_test/downloads

http://firmata.org/wiki/Main_Page

https://www.cnblogs.com/sjqlwy/p/lattepanda_firmata.html

Using Firmata to control Arduino by Processing

Arduino Program:
Standard Firmata example
Processing:(need to install the arduino first)
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
int ledPin = 13;

void setup()
{
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600); 
// the Arduinio.list()[0] can be replace as "COM12"
  arduino.pinMode(ledPin, Arduino.OUTPUT);
}

void draw()
{
  arduino.digitalWrite(ledPin, Arduino.HIGH);
  delay(1000);
  arduino.digitalWrite(ledPin, Arduino.LOW);
  delay(1000);
}

offline-mesh-network

Migrate from https://cmakerhk.wordpress.com/2018/09/30/offline-mesh-network/


https://www.youtube.com/watch?v=i5aJAzZobBQ
Gotoky: bluetooth device which allow us to communcation though a long distance without cellular signals.

Firechat, use Smartphone WIFI and BLUETOOTH –> the range is only 30 step

BluCat: https://www.youtube.com/watch?v=39fNxtTJtis
https://www.opengarden.com/firechat/

https://play.google.com/store/apps/details?id=com.bsb.hike&hl=en
HIKE, Bridgefy, firechat

Multipeer Connectivity Framework: Similar tech
https://www.gotoky.com/

https://www.gotenna.com/

https://www.youtube.com/watch?v=hc5bdnqd4xk

https://www.youtube.com/watch?v=ECbycIML0Us

Brief notes on ESP8266 or ESP32

migrate from https://cmakerhk.wordpress.com/2018/09/28/brief-notes-on-esp8266-or-esp32/


nodeMCU is a 3rd party of esp8266 with aid circuit.

There are muiltiple ways to use ESP8266:

Method 1 ESP8266 AT Bin V1.7.0 - Control AT Mode This allows you communicate with ESP8266 though USART with AT command, you can find this firmware on ESPRESSIF website
Method 2 nodeMCU Firmware This Firmware allows you to write Lua Script to run on ESP8266
Method 3 Arduino IDE By adding the hardware library to Arduino IDE, this allows you to write code on Arduino IDE, and use the similar syntax on Arduino on ESP8266
Method 4 Official SDK It provides two SDK, NONOS SDK, and FreeRTOS SDK, this allows you to write C lang and official API on the ESP8266 chip
M1 you must have something to send the AT Command

M2, M3, M4 allow you to build standalone ESP8266 program

AT, NONOS, FreeRTOS:
https://www.espressif.com/en/products/hardware/esp8266ex/resources

nodeMCU:
https://github.com/nodemcu/nodemcu-firmware
https://github.com/nodemcu/nodemcu-firmware/blob/master/docs/en/flash.md

Arduino IDE:
https://github.com/esp8266/Arduino

Some information online is quite confusing. With Arduino connecting the ESP8266 but using the Arduino IDE, Some are AT command, Some are using the Arduino IDE hardware library………….

##It is fking hard to find the information online…… I spend a whole month to figure out all the relationship ((( don’t blame me stupid

ESP-Link:
https://github.com/jeelabs/esp-link
https://github.com/arduino-org/Esp-Link

notes-sizeof-strlen

migrate from https://cmakerhk.wordpress.com/2018/09/28/sizeof-vs-strlen/


Sizeof()

#include
int main()
{
printf("%d\n",sizeof(char)); // output 1
printf("%d\n",sizeof(int)); // output 4
printf("%d\n",sizeof(float));// output 4
printf("%d", sizeof(double));// output 8
return 0;
}
Sizeof will return the size of the variable
#include
int main()
{
int arr[] = {1, 2, 3, 4, 7, 98, 0, 12, 35, 99, 14};
printf("Number of elements :%d", sizeof(arr)/sizeof(arr[0]));
return 0;
}
Number of elements :11
This is useful for getting the number of the elements of an array.

allocate memory dynamically - To allocate block of memory dynamically.

int *ptr = malloc(10*sizeof(int));
strlen()
size_t strlen(const char *str)
not include \0

//========compare

Since strlen() not inlclude \0

// C program to demonstrate difference
// between strlen() and sizeof()
#include
#include
int main()
{
char str[] = "November";
printf("Length of String is %d\n", strlen(str)); //8
printf("Size of String is %d\n", sizeof(str)); //9
}
#include
#include
using namespace std;
int main()
{
char a[] = {"Geeks for"};
char b[] = {'G','e','e','k','s',' ','f','o','r'}; //9 char total
cout << "sizeof(a) = " << sizeof(a);
cout << "\nstrlen(a) = "<< strlen(a);
cout<< "\nsizeof(b) = " << sizeof(b);
cout<< "\nstrlen(b) = " << strlen(b);
return 0;
}
sizeof(a): 10 //include the NULL at the end

strlen(a): 9 // not include the NULL

sizeof(b): 9 // total 9 char ma

strlen(b):11 // abnormal

ref:

https://www.geeksforgeeks.org/sizeof-operator-c/

https://www.tutorialspoint.com/c_standard_library/c_function_strlen.htm

https://www.geeksforgeeks.org/difference-strlen-sizeof-string-c-reviewed/

notes-on-memset

migrate from https://cmakerhk.wordpress.com/2018/09/28/memset/


void *memset(void *str, int c, size_t n)

memset use set the value be c at pointer str n times and return pointer str

str is a void pointer, so that you can pass in any type.

#include 
#include 

int main ()
{
   char str[50];

   strcpy(str,"Hello World");
   puts(str);

   memset(str,'$',2);
   puts(str);

   return(0);
}

Hello World
$$llo World

memset(str, 0, sizeof(str)); //Empty str