关于ALPHA ESP8285 示例程序“测试ADC以及WIFI” 的疑问
很高兴地发现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!
// ADS1015ADS1115
// --------------
// ads.setGain(GAIN_TWOTHIRDS);// 2/3x gain +/- 6.144V1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain+/- 0.256V1 bit = 0.125mV0.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() {
}
然而我目前还未测试过的,祝圣诞快乐 我来回答你第一个问题,因为这个例程是我写的,,,,,,网络连接跟ADC的确是互不相关的,之所以在程序里面加了ADC,主要是需要测试ADC芯片是否是真的。。。因为之前一批买的是假货。。。网络连接是为了测试8285是否正常工作。。。。。。
至于你的第二个问题嘛。。。fingerprint在哪里出现啊? 董董soul 发表于 2019-2-15 13:38
我来回答你第一个问题,因为这个例程是我写的,,,,,,网络连接跟ADC的确是互不相关的,之所以在程序里 ...
fingerprint的位置在35行
wing 发表于 2019-2-16 11:15
fingerprint的位置在35行
引用的例程在这里,你可以去看例程,例程是说通过HTTPS的方式访问GITHUB的API,fingerprin是密钥
页:
[1]