임베디드 보드/아두이노

WEMOS D1 전류/전압 측정, ThingSpeak 데이터 모니터링

ZEROWIN.TECH 2020. 8. 21. 01:31
728x90

Data collection in the cloud with advanced data analysis using MATLAB

https://thingspeak.com/

 

IoT Analytics - ThingSpeak Internet of Things

Weather Station This project shows how to build an Arduino-based weather station that sends data to ThingSpeak. Once the data is collected, MATLAB is used to view trends of the data, plot histograms of the data, calculate dew point from the raw temperature

thingspeak.com

ThingSpeak

MATLAB을 사용한 고급 데이터 분석을 통해 클라우드에서 데이터 수집

수집한 데이터 모니텅링 사이트 링크

 

https://thingspeak.com/channels/561530

 

Solar TEST - ThingSpeak IoT

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to

thingspeak.com

ThingSpeak는 인터넷이나 LAN을 통해 HTTP 및 MQTT 프로토콜을 사용하여 사물에서 데이터를 저장하고 검색하는 오픈 소스 사물 인터넷 (IoT) 애플리케이션 및 API입니다. 아두이노 와 센서를 이용하여 데이터를 만듭니다.

ThingSpeak는 로깅 응용 프로그램, 위치 추적 응용 프로그램 및 상태 업데이트가있는 사물의 소셜 네트워크입니다.

 

학생 및 교육자를위한 ThingSpeak
내장 된 MATLAB 데이터 분석 도구 및 실시간 센서 데이터 수집으로 IoT 연구 프로젝트를 빠르게 구현


ThingSpeak for Air Quality Monitoring
대기 질 센서의 원격 모니터링을위한 IoT 서비스를 구축하고 오염 수준을 예측하는 MATLAB 모델을 생성합니다.


에너지 모니터링을위한 ThingSpeak
에너지 사용량을 모니터링하는 IoT 애플리케이션을 구축하고 전력 서명 식별 및 부하 예측을위한 MATLAB 모델 개발


ThingSpeak for Smart Farming
농장에 배포 된 센서의 원격 모니터링을위한 애플리케이션을 구축하고 MATLAB 모델을 개발하여 작물 수확량을 늘리고 비용을 절감하십시오.

 

WEMOS D1

INA219 전류 / 전압 모니터링 센서

26V, 12-bit, i2c output current/voltage/power monitor

https://www.ti.com/product/INA219?utm_source=google&utm_medium=cpc&utm_campaign=asc-null-null-GPN_EN-cpc-pf-google-kr&utm_content=INA219&ds_k=INA219&DCM=yes&gclid=Cj0KCQjwvvj5BRDkARIsAGD9vlJKbdqgPKBvz203FvXXONIa2OFEuWAMVAKEy6uBayiI_b0_WdAc2SEaApMaEALw_wcB&gclsrc=aw.ds#product-details##features

INA219는 I2C 또는 SMBUS 호환 인터페이스가있는 전류 및 전력 모니터입니다. 이 장치는 프로그래밍 가능한 변환 시간 및 필터링을 사용하여 전압 강하와 버스 공급 전압을 모두 모니터링합니다. 내부 승수와 결합 된 프로그래밍 가능한 교정 값은 전류를 암페어 단위로 직접 판독 할 수 있습니다. 추가 곱셈 레지스터는 전력을 와트 단위로 계산합니다. I2C 또는 SMBUS 호환 인터페이스에는 16 개의 프로그래밍 가능한 주소가 있습니다.

INA219는 A 및 B의 두 가지 등급으로 제공됩니다. B 등급 버전은 더 높은 정확도와 더 높은 정밀도 사양을 제공합니다.

INA219는 0V에서 26V까지 다양 할 수있는 버스의 쇼트를 감지합니다.이 장치는 단일 3V ~ 5.5V 공급을 사용하여 최대 1mA의 공급 전류를 끌어냅니다. INA219는 –40 ° C ~ 125 ° C에서 작동합니다.

 

LTE MOBILE ROUTER

언제 어디서나 LTE 속도로 인터넷을 이용할 수 있는 휴대용 와이파이 공유기

외부에서 LTE 모바일 라우터를 이용하여 인터넷 기기를 사용할 수 있습니다.

WEMOS D1 보드에서 전류/전압 데이터를 ThingSpeak 서버로 전송할 때 사용됩니다.

https://www.uplus.co.kr/biz/m2m/mmtom/InitBzMobRouter.hpi

 

모바일라우터 < 무선인터넷 | LG U+

제 어디서나 LTE 속도로 인터넷을 이용할 수 있는 휴대용 와이파이 공유기

www.uplus.co.kr

PROGRAMMING

아두이노 보드에서 WIFI를 이용하여 ThingSpeak 에 접속하여 전압/전류 데이터를 전송합니다.

#include <Wire.h>
#include <Adafruit_INA219.h>

#include <ESP8266WiFi.h>
#include <stdlib.h>

 
Adafruit_INA219 ina219;

//char ssid[] = "ZEROWIN";         // your network SSID (name)
//char pass[] = "zzzzzzzz";        // your network password

char ssid[] = "xxxxxxxx"; // LTE MOBILE ROUTER
char pass[] = "xxxxxxxx";

String apiKey = "PEBVKEUA9135PMYK";
const char* host = "api.thingspeak.com"; // "www.google.co.kr";

 // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  
void setup() {
	  // put your setup code here, to run once:
	  Serial.begin(115200);

	  if (! ina219.begin()) {
		Serial.println(F("Failed to find INA219 chip"));
		while (1) 
		{ 
		  delay(10); 
		}
	  }
	  
	  WiFi.begin(ssid, pass); // 와이파이에 연결하는 함수 입니다.
			  
	  // 와이파이에 연결이 될 때 까지 대기
	  while (WiFi.status() != WL_CONNECTED) {
		delay(500);
		Serial.print(".");
	  }
	  
	  Serial.println("");
	  Serial.println("WiFi connected");  
	  Serial.println("IP address: ");
	  Serial.println(WiFi.localIP());// 아이피 주소를 출력합니다.
}

#define MAX_NUM_CURRENT 10
float average_current[MAX_NUM_CURRENT] = { 0, };

int loop_count = 0;
int iSendDataToThingSpeakTimeout = 0;

void loop() {

  loop_count += 1;
  
  // put your main code here, to run repeatedly:
	float shuntvoltage = 0;
	float busvoltage = 0;
	float current_mA = 0;
	float loadvoltage = 0;
	float power_mW = 0;

	shuntvoltage = ina219.getShuntVoltage_mV();
	busvoltage = ina219.getBusVoltage_V();
	current_mA = ina219.getCurrent_mA();
	power_mW = ina219.getPower_mW();
	loadvoltage = busvoltage + (shuntvoltage / 1000);
	
	Serial.print(F("Load Voltage:  ")); Serial.print(loadvoltage); Serial.println(" V");
	Serial.print(F("Current:       ")); Serial.print(current_mA);  // Serial.println(" mA");
	
	average_current[loop_count % MAX_NUM_CURRENT] = current_mA;
	
	double total = 0;
	for(int i = 0; i < MAX_NUM_CURRENT; i++)
	{
		total += average_current[i];
	}
	
	
	double average = total / MAX_NUM_CURRENT;
	if(loop_count < MAX_NUM_CURRENT) average = total / loop_count;
	
	Serial.print(","); Serial.print(average);
	Serial.println(" mA");

   // https://api.thingspeak.com/update?api_key=Z4YBOPVSUUVWXH2D&field1=20&field2=60
    iSendDataToThingSpeakTimeout += 1;
    if(iSendDataToThingSpeakTimeout % 30 == 0) // per 30 sec
    {
        if (!client.connect(host, httpPort)) {
          Serial.println("connection failed");
          // return;
        }
        else { 
//          client.print(String("GET /update?api_key=Z4YBOPVSUUVWXH2D&field1=20&field2=60 HTTP/1.1\r\n
          String http_line = "GET /update?api_key=";
          http_line += apiKey;
          http_line += "&field1=";
          http_line += String(loadvoltage);
          http_line += "&field2=";
          http_line += String(average);
          http_line += " HTTP/1.1\r\n";
          client.print(http_line);
          
            client.print(String("Host: api.thingspeak.com\r\n\
            Connection: keep-alive\r\n\r\n\
            Cache-Control: max-age=0\r\n\
            Upgrade-Insecure-Requests: 1\r\n\
            User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36\r\n\
            Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*//*;q=0.8\r\n\
            Accept-Encoding: gzip, deflate, br\r\n"));
        }        

       // Read all the lines of the reply from server and print them to Serial
       while(client.available()) { //서버로부터 받은 응답을 출력합니다.
          
          String line = client.readString();
          int len = line.length();
          Serial.println(line);
          
       }        
  
       // if the server's disconnected, stop the client:
       if (!client.connected() ) {
          Serial.println();
          Serial.println("disconnecting from server.");
          client.stop();
       }    
    } 
    
	
	delay(1000);
}

Publish to a Channel Using an Arduino client

https://kr.mathworks.com/help/thingspeak/use-arduino-client-to-publish-to-a-channel.html

 

Publish to a Channel Using an Arduino Client - MATLAB & Simulink - MathWorks 한국

귀하의 시스템에 이 예제의 수정된 버전이 있습니다. 이 버전을 대신 여시겠습니까?

kr.mathworks.com

테스트 

아래 사이트 링크에 접속하면 데이터를 모니터링 할 수 있습니다.

건물 옥상에 태양광과 같이 설치하여 전압 / 전류 데이터를 모니터링합니다.

사용자보드에서 소비되는 전류/전압을 측정합니다. 그리고 낮에는 태양광 충전과 배터리를 모니터링합니다.

https://thingspeak.com/channels/561530

 

Solar TEST - ThingSpeak IoT

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to

thingspeak.com