极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 21317|回复: 3

关于ALPHA ESP8285 示例程序“测试ADC以及WIFI” 的疑问

[复制链接]
发表于 2018-12-25 15:30:26 | 显示全部楼层 |阅读模式

很高兴地发现OC主页的一些产品信息得到更新,尽管8285的硬件参数还没完全改对,但还是增加了不少例程。

其中令我印象深刻的是“测试ADC以及WIFI” 示例程序,在此之前我从来没想怎么用8285来访问https。
不过同时也带来了一些疑问:

1 该示例的网络连接和ADC读取是完全独立毫不相干的吧?
2 关于fingerprint的值,注释上说从浏览器上查看,那么这个值是永恒固定的么?还是说过一段时间会变?


地址 http://www.ocrobot.com/doku.php?id=ocrobot:alpha:esp8285:main
附代码

  1. /*
  2. *  HTTP over TLS (HTTPS) example sketch
  3. *
  4. *  This example demonstrates how to use
  5. *  WiFiClientSecure class to access HTTPS API.
  6. *  We fetch and display the status of
  7. *  esp8266/Arduino project continuous integration
  8. *  build.
  9. *
  10. *  Limitations:
  11. *    only RSA certificates
  12. *    no support of Perfect Forward Secrecy (PFS)
  13. *    TLSv1.2 is supported since version 2.4.0-rc1
  14. *
  15. *  Created by Ivan Grokhotkov, 2015.
  16. *  This example is in public domain.
  17. */

  18. #include <ESP8266WiFi.h>
  19. #include <WiFiClientSecure.h>
  20. #include <Wire.h>
  21. #include <Adafruit_ADS1015.h>

  22. // Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
  23. Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

  24. const char* ssid = "OCROBOT";
  25. const char* password = "jikegongfang";

  26. const char* host = "api.github.com";
  27. const int httpsPort = 443;

  28. // Use web browser to view and copy
  29. // SHA1 fingerprint of the certificate
  30. const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";

  31. void setup() {
  32.   Serial.println("Hello!");

  33.   Serial.println("Getting single-ended readings from AIN0..3");
  34.   Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");

  35.   // The ADC input range (or gain) can be changed via the following
  36.   // functions, but be careful never to exceed VDD +0.3V max, or to
  37.   // exceed the upper and lower limits if you adjust the input range!
  38.   // Setting these values incorrectly may destroy your ADC!
  39.   //                                                                ADS1015  ADS1115
  40.   //                                                                -------  -------
  41.   // ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  42.   // ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  43.   // ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  44.   // ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
  45.   // ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
  46.   // ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV

  47.   ads.begin();
  48.   Serial.begin(115200);
  49.   Serial.println();
  50.   Serial.print("connecting to ");
  51.   Serial.println(ssid);
  52.   WiFi.mode(WIFI_STA);
  53.   WiFi.begin(ssid, password);
  54.   while (WiFi.status() != WL_CONNECTED) {
  55.     delay(500);
  56.     Serial.print(".");
  57.   }
  58.   Serial.println("");
  59.   Serial.println("WiFi connected");
  60.   Serial.println("IP address: ");
  61.   Serial.println(WiFi.localIP());

  62.   // Use WiFiClientSecure class to create TLS connection
  63.   WiFiClientSecure client;
  64.   Serial.print("connecting to ");
  65.   Serial.println(host);
  66.   if (!client.connect(host, httpsPort)) {
  67.     Serial.println("connection failed");
  68.     return;
  69.   }

  70.   if (client.verify(fingerprint, host)) {
  71.     Serial.println("certificate matches");
  72.   } else {
  73.     Serial.println("certificate doesn't match");
  74.   }

  75.   String url = "/repos/esp8266/Arduino/commits/master/status";
  76.   Serial.print("requesting URL: ");
  77.   Serial.println(url);

  78.   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  79.                "Host: " + host + "\r\n" +
  80.                "User-Agent: BuildFailureDetectorESP8266\r\n" +
  81.                "Connection: close\r\n\r\n");

  82.   Serial.println("request sent");
  83.   while (client.connected()) {
  84.     String line = client.readStringUntil('\n');
  85.     if (line == "\r") {
  86.       Serial.println("headers received");
  87.       break;
  88.     }
  89.   }
  90.   String line = client.readStringUntil('\n');
  91.   if (line.startsWith("{"state":"success"")) {
  92.     Serial.println("esp8266/Arduino CI successfull!");
  93.   } else {
  94.     Serial.println("esp8266/Arduino CI has failed");
  95.   }
  96.   Serial.println("reply was:");
  97.   Serial.println("==========");
  98.   Serial.println(line);
  99.   Serial.println("==========");
  100.   Serial.println("closing connection");
  101.    int16_t adc0, adc1, adc2, adc3;

  102.   adc0 = ads.readADC_SingleEnded(0);
  103.   adc1 = ads.readADC_SingleEnded(1);
  104.   adc2 = ads.readADC_SingleEnded(2);
  105.   adc3 = ads.readADC_SingleEnded(3);
  106.   Serial.print("AIN0: "); Serial.println(adc0);
  107.   Serial.print("AIN1: "); Serial.println(adc1);
  108.   Serial.print("AIN2: "); Serial.println(adc2);
  109.   Serial.print("AIN3: "); Serial.println(adc3);
  110.   Serial.println(" ");

  111.   delay(1000);
  112. }

  113. void loop() {

  114. }
复制代码





然而我目前还未测试过的,祝圣诞快乐
回复

使用道具 举报

发表于 2019-2-15 13:38:12 | 显示全部楼层
我来回答你第一个问题,因为这个例程是我写的,,,,,,网络连接跟ADC的确是互不相关的,之所以在程序里面加了ADC,主要是需要测试ADC芯片是否是真的。。。因为之前一批买的是假货。。。网络连接是为了测试8285是否正常工作。。。。。。
至于你的第二个问题嘛。。。fingerprint在哪里出现啊?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-2-16 11:15:08 | 显示全部楼层
董董soul 发表于 2019-2-15 13:38
我来回答你第一个问题,因为这个例程是我写的,,,,,,网络连接跟ADC的确是互不相关的,之所以在程序里 ...

fingerprint的位置在35行



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2019-2-18 14:27:24 | 显示全部楼层
wing 发表于 2019-2-16 11:15
fingerprint的位置在35行


引用的例程在这里,你可以去看例程,例程是说通过HTTPS的方式访问GITHUB的API,fingerprin是密钥

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 22:45 , Processed in 0.051465 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表