很高兴地发现OC主页的一些产品信息得到更新,尽管8285的硬件参数还没完全改对,但还是增加了不少例程。
其中令我印象深刻的是“测试ADC以及WIFI” 示例程序,在此之前我从来没想怎么用8285来访问https。
不过同时也带来了一些疑问:
1 该示例的网络连接和ADC读取是完全独立毫不相干的吧?
2 关于fingerprint的值,注释上说从浏览器上查看,那么这个值是永恒固定的么?还是说过一段时间会变?
地址 http://www.ocrobot.com/doku.php?id=ocrobot:alpha:esp8285:main
附代码
- /*
- * HTTP over TLS (HTTPS) example sketch
- *
- * This example demonstrates how to use
- * WiFiClientSecure class to access HTTPS API.
- * We fetch and display the status of
- * esp8266/Arduino project continuous integration
- * build.
- *
- * Limitations:
- * only RSA certificates
- * no support of Perfect Forward Secrecy (PFS)
- * TLSv1.2 is supported since version 2.4.0-rc1
- *
- * Created by Ivan Grokhotkov, 2015.
- * This example is in public domain.
- */
-
- #include <ESP8266WiFi.h>
- #include <WiFiClientSecure.h>
- #include <Wire.h>
- #include <Adafruit_ADS1015.h>
-
- // Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
- Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
-
- const char* ssid = "OCROBOT";
- const char* password = "jikegongfang";
-
- const char* host = "api.github.com";
- const int httpsPort = 443;
-
- // Use web browser to view and copy
- // SHA1 fingerprint of the certificate
- const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
-
- void setup() {
- Serial.println("Hello!");
-
- Serial.println("Getting single-ended readings from AIN0..3");
- Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
-
- // The ADC input range (or gain) can be changed via the following
- // functions, but be careful never to exceed VDD +0.3V max, or to
- // exceed the upper and lower limits if you adjust the input range!
- // Setting these values incorrectly may destroy your ADC!
- // ADS1015 ADS1115
- // ------- -------
- // ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
- // ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
- // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
- // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
- // ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
- // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
-
- ads.begin();
- Serial.begin(115200);
- Serial.println();
- Serial.print("connecting to ");
- Serial.println(ssid);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
-
- // Use WiFiClientSecure class to create TLS connection
- WiFiClientSecure client;
- Serial.print("connecting to ");
- Serial.println(host);
- if (!client.connect(host, httpsPort)) {
- Serial.println("connection failed");
- return;
- }
-
- if (client.verify(fingerprint, host)) {
- Serial.println("certificate matches");
- } else {
- Serial.println("certificate doesn't match");
- }
-
- String url = "/repos/esp8266/Arduino/commits/master/status";
- Serial.print("requesting URL: ");
- Serial.println(url);
-
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "User-Agent: BuildFailureDetectorESP8266\r\n" +
- "Connection: close\r\n\r\n");
-
- Serial.println("request sent");
- while (client.connected()) {
- String line = client.readStringUntil('\n');
- if (line == "\r") {
- Serial.println("headers received");
- break;
- }
- }
- String line = client.readStringUntil('\n');
- if (line.startsWith("{"state":"success"")) {
- Serial.println("esp8266/Arduino CI successfull!");
- } else {
- Serial.println("esp8266/Arduino CI has failed");
- }
- Serial.println("reply was:");
- Serial.println("==========");
- Serial.println(line);
- Serial.println("==========");
- Serial.println("closing connection");
- int16_t adc0, adc1, adc2, adc3;
-
- adc0 = ads.readADC_SingleEnded(0);
- adc1 = ads.readADC_SingleEnded(1);
- adc2 = ads.readADC_SingleEnded(2);
- adc3 = ads.readADC_SingleEnded(3);
- Serial.print("AIN0: "); Serial.println(adc0);
- Serial.print("AIN1: "); Serial.println(adc1);
- Serial.print("AIN2: "); Serial.println(adc2);
- Serial.print("AIN3: "); Serial.println(adc3);
- Serial.println(" ");
-
- delay(1000);
- }
-
- void loop() {
-
- }
复制代码
然而我目前还未测试过的,祝圣诞快乐 |