1 / 26

15 架站設定

15 架站設定. 機械系 洪振聰. >mkdir myapp & cd myapp. 安裝 Express. > npm init. 安裝 Express. https://expressjs.com/en/starter/generator.html. > npm install express --save. > npm install express-generator -g. const express = require('express'); const app = express(); // 建立一個 Express 伺服器

Download Presentation

15 架站設定

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 15 架站設定 機械系 洪振聰

  2. >mkdir myapp&cd myapp

  3. 安裝Express >npm init

  4. 安裝Express https://expressjs.com/en/starter/generator.html

  5. >npm install express --save

  6. >npm install express-generator -g

  7. const express = require('express'); const app = express(); //建立一個Express伺服器 app.get('/', function (req, res) { res.send('Express is excellent!') }); app.listen(3000, function () { console.log('Example app is running on port 3000!');} );

  8. https://codeburst.io/build-a-weather-website-in-30-minutes-with-node-js-express-openweather-a317f904897bhttps://codeburst.io/build-a-weather-website-in-30-minutes-with-node-js-express-openweather-a317f904897b How to use EJS in Express http://robdodson.me/how-to-use-ejs-in-express/ Express 教學 2: 創建一個骨架網站 https://developer.mozilla.org/zh-TW/docs/Learn/Server-side/Express_Nodejs/skeleton_website

  9. 如何查詢電腦的IP與網卡MAC

  10. /* DHCP-based IP printer This sketch uses the DHCP extensions to the Ethernet library to get an IP address via DHCP and print the address obtained. using an Arduino Wiznet Ethernet shield. Circuit: Ethernet shield attached to pins 10, 11, 12, 13 created 12 April 2011 modified 9 Apr 2012 by Tom Igoe modified 02 Sept 2015 by Arturo Guadalupi */ #include <SPI.h> #include <Ethernet.h> // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0x9E, 0x15, 0x1E, 0x41, 0x62, 0x5B }; void setup() { // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields //Ethernet.init(5); // MKR ETH shield //Ethernet.init(0); // Teensy 2.0 //Ethernet.init(20); // Teensy++ 2.0 //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); } else if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // no point in carrying on, so do nothing forevermore: while (true) { delay(1); } } // print your local IP address: Serial.print("My IP address: "); Serial.println(Ethernet.localIP()); } void loop() { switch (Ethernet.maintain()) { case 1: //renewed fail Serial.println("Error: renewed fail"); break; case 2: //renewed success Serial.println("Renewed success"); //print your local IP address: Serial.print("My IP address: "); Serial.println(Ethernet.localIP()); break; case 3: //rebind fail Serial.println("Error: rebind fail"); break; case 4: //rebind success Serial.println("Rebind success"); //print your local IP address: Serial.print("My IP address: "); Serial.println(Ethernet.localIP()); break; default: //nothing happened break; } }

  11. /* DHCP Chat Server A simple server that distributes any incoming messages to all connected clients. To use, telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. THis version attempts to get an IP address using DHCP Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 modified 9 Apr 2012 by Tom Igoe modified 02 Sept 2015 by Arturo Guadalupi Based on ChatServer example by David A. Mellis */ #include <SPI.h> #include <Ethernet.h> // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: byte mac[] = { 0x44, 0x8A, 0x5B, 0xA0, 0xC8, 0x3B }; IPAddress ip(192, 168, 0, 106); IPAddress myDns(192, 168, 1, 1); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); // telnet defaults to port 23 EthernetServer server(23); bool gotAMessage = false; // whether or not you got a message from the client yet void setup() { // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields //Ethernet.init(5); // MKR ETH shield //Ethernet.init(0); // Teensy 2.0 //Ethernet.init(20); // Teensy++ 2.0 //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // start the Ethernet connection: Serial.println("Trying to get an IP address using DHCP"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // initialize the Ethernet device not using DHCP: Ethernet.begin(mac, ip, myDns, gateway, subnet); } // print your local IP address: Serial.print("My IP address: "); Serial.println(Ethernet.localIP()); // start listening for clients server.begin(); } void loop() { // wait for a new client: EthernetClient client = server.available(); // when the client sends the first byte, say hello: if (client) { if (!gotAMessage) { Serial.println("We have a new client"); client.println("Hello, client!"); gotAMessage = true; } // read the bytes incoming from the client: char thisChar = client.read(); // echo the bytes back to the client: server.write(thisChar); // echo the bytes to the server as well: Serial.print(thisChar); Ethernet.maintain(); } }

  12. #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_ADXL345_U.h> /* Assign a unique ID to this sensor at the same time */ Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345); void displaySensorDetails(void) { sensor_t sensor; accel.getSensor(&sensor); Serial.println("------------------------------------"); Serial.print ("Sensor: "); Serial.println(sensor.name); Serial.print ("Driver Ver: "); Serial.println(sensor.version); Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2"); Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2"); Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2"); Serial.println("------------------------------------"); Serial.println(""); delay(500); } void displayDataRate(void) { Serial.print ("Data Rate: "); switch(accel.getDataRate()) { case ADXL345_DATARATE_3200_HZ: Serial.print ("3200 "); break; case ADXL345_DATARATE_1600_HZ: Serial.print ("1600 "); break; case ADXL345_DATARATE_800_HZ: Serial.print ("800 "); break; case ADXL345_DATARATE_400_HZ: Serial.print ("400 "); break; case ADXL345_DATARATE_200_HZ: Serial.print ("200 "); break; case ADXL345_DATARATE_100_HZ: Serial.print ("100 "); break; case ADXL345_DATARATE_50_HZ: Serial.print ("50 "); break; case ADXL345_DATARATE_25_HZ: Serial.print ("25 "); break; case ADXL345_DATARATE_12_5_HZ: Serial.print ("12.5 "); break; case ADXL345_DATARATE_6_25HZ: Serial.print ("6.25 "); break; case ADXL345_DATARATE_3_13_HZ: Serial.print ("3.13 "); break; case ADXL345_DATARATE_1_56_HZ: Serial.print ("1.56 "); break; case ADXL345_DATARATE_0_78_HZ: Serial.print ("0.78 "); break; case ADXL345_DATARATE_0_39_HZ: Serial.print ("0.39 "); break; case ADXL345_DATARATE_0_20_HZ: Serial.print ("0.20 "); break; case ADXL345_DATARATE_0_10_HZ: Serial.print ("0.10 "); break; default: Serial.print ("???? "); break; } Serial.println(" Hz"); } void displayRange(void) { Serial.print ("Range: +/- "); switch(accel.getRange()) { case ADXL345_RANGE_16_G: Serial.print ("16 "); break; case ADXL345_RANGE_8_G: Serial.print ("8 "); break; case ADXL345_RANGE_4_G: Serial.print ("4 "); break; case ADXL345_RANGE_2_G: Serial.print ("2 "); break; default: Serial.print ("?? "); break; } Serial.println(" g"); } void setup(void) { #ifndef ESP8266 while (!Serial); // for Leonardo/Micro/Zero #endif Serial.begin(9600); Serial.println("Accelerometer Test"); Serial.println(""); /* Initialise the sensor */ if(!accel.begin()) { /* There was a problem detecting the ADXL345 ... check your connections */ Serial.println("Ooops, no ADXL345 detected ... Check your wiring!"); while(1); } /* Set the range to whatever is appropriate for your project */ accel.setRange(ADXL345_RANGE_16_G); // accel.setRange(ADXL345_RANGE_8_G); // accel.setRange(ADXL345_RANGE_4_G); // accel.setRange(ADXL345_RANGE_2_G); /* Display some basic information on this sensor */ displaySensorDetails(); /* Display additional settings (outside the scope of sensor_t) */ displayDataRate(); displayRange(); Serial.println(""); } void loop(void) { /* Get a new sensor event */ sensors_event_t event; accel.getEvent(&event); /* Display the results (acceleration is measured in m/s^2) */ Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" "); Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" "); Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 "); delay(500); }

  13. 本單元結束

More Related