윈도우 7 은 무선 인터넷 부터 확인해야한다

이 익숙한ㅇ 꽃개 모양 애 열어주고 없으면 설치할것 

저기에 액세스 들어간다

그리고

아두이노 SSID 를 적어서 주소를 맞쳐주고 네트워크는 WPA2=PSK로 하자 왠지 모름

 

비밀번호 처서 연결해준다

그럼 본인의 피씨가 핫스팟이 되어 외부 네트워크랑 공유가 가능하게 만들어준다

이런 코드표가 있다 

참고를 하여 주소의 값을 가져와야 하는데 

저기 트릭이라고 저거 불러오면 된다 

핀번호는 아두이노 할때 설정값인 걸로 알고 있다

 

 

설정값은 이렇게 장치 추가 해주고

이런식으로 추가를 해준다 

그러면 불러오기가 가능해진다

통신을 만들어줄 서버와 확인할거 CMD 틀어주고

써버임 위에거

 

이건 확인차 열어놓은거

 

 

이거할려면 mosquitto 따운 해야함 

.

https://story-of-flower.tistory.com/233

 

모스키토 통신 사용하기 windows X-SCADA

https://deneb21.tistory.com/416 MQTT 개념과 Mosquitto 설치 및 사용 이번에는 사물인터넷에서 각광 받고 있는 메시지 전송 프로토콜인 MQTT (Message Queue Telemetry Transport) 에 대해서 알아보겠습니다. M..

story-of-flower.tistory.com

 

여기에서 확인하여 다운하면됨

 

실행하면 끝

블로그 이미지

Or71nH

,

 

ESP8266_AT_Instruction_Set_v0_22.pdf
1.01MB
at_cmd1.ino
0.00MB

/*
--------------------------------------------------
아두이노 우노 핀    ESP8266 Serial WIFI 모듈  핀
  3.3V              VCC, CH_PD
 D0(TX)             RX (레벨쉬프트 사용)
 D1(RX)             TX
 GND                GND
 ------------------------------------------------
시리얼 모니터 115200bps 설정, Toth NL & CR 설정 후 아래 명령 실행
AT+RST                       //restart
AT+UART_DEF=9600,8,1,0,0    
시리얼 모니터 9600pbs 설정 변경후  
AT+RST              //응답 확인
*/

void setup() {
  // put your setup code here, to run once:
//  Serial.begin(9600) ;
//  Serial.println("AT CMD TEST 1");
}

void loop() {
  // put your main code here, to run repeatedly:

}

처음에 설정해주고 그다음부턴 9600 보드레이트 들어가면된다

처음에는 아마도 115200 일것이다

 

 

 

 

at_cmd2.ino
0.00MB

 

/*
--------------------------------------------------
아두이노 우노 핀    ESP8266 Serial WIFI 모듈  핀
  3.3V              VCC, CH_PD
 D7(TX)             RX (레벨쉬프트 사용)
 D6(RX)             TX
 GND                GND
 ------------------------------------------------
//시리얼 모니터 115200 설정, Both NL & CR 설정 후 아래 명령 실행
AT+RST    ==>  응답확인 : 핀 연결 및 모듈 테스트 
*/

SoftwareSerial wifi(6, 7) ;  // RX, TX
void setup() {
  // put your setup code here, to run once:
  wifi.begin(9600) ;
  Serial.begin(115200) ;
//  Serial.println("AT CMD TEST 2");
}



void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available()) wifi.write(Serial.read()) ;
  if (wifi.available()) Serial.write(wifi.read()) ;
}

 보드레이트는 115200 으로 하면 된다

 

 

그리고 디지털  0 에 있던걸 7 에 1 에 있던걸 6에 꽃아줘야한다!!!!!!!!!!!!!!!

 

 

받으면

WebClient 예제를 만들어주고

와이파이만 바꿔주자

 

오오오ㅗ오오오

오옹오오오오오오오!!!!!

됫어

wifi_client.ino
0.00MB

/*
 WiFiEsp test: ClientTest
http://www.kccistc.net/
작성일 : 2019.12.17 
작성자 : IoT 임베디드 KSH
*/
#define DEBUG_WIFI
#define AP_SSID "smartmes"
#define AP_PASS "smartmes0"
#define SERVER_NAME "192.168.0.31"
#define SERVER_PORT 5000   

#define WIFITX 9  //9:TX -->ESP8266 RX
#define WIFIRX 10 //10:RX-->ESP8266 TX
           
#include "WiFiEsp.h"
#include "SoftwareSerial.h"

SoftwareSerial wifiSerial(WIFIRX, WIFITX); 
WiFiEspClient client;
 
void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200); //DEBUG
    wifi_Setup();
}

void loop() {
  // put your main code here, to run repeatedly:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
}
void wifi_Setup() {
  wifiSerial.begin(9600);
  wifi_Init();
  server_Connect();
}
void wifi_Init()
{
  do {
    WiFi.init(&wifiSerial);
    if (WiFi.status() == WL_NO_SHIELD) {
#ifdef DEBUG_WIFI    
      Serial.println("WiFi shield not present");
#endif 
    }
    else
      break;   
  }while(1);

#ifdef DEBUG_WIFI    
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(AP_SSID);
#endif     
    while(WiFi.begin(AP_SSID, AP_PASS) != WL_CONNECTED) {   
#ifdef DEBUG_WIFI  
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(AP_SSID);   
#endif   
    }
#ifdef DEBUG_WIFI      
  Serial.println("You're connected to the network");    
  printWifiStatus();
#endif 
}
int server_Connect()
{
#ifdef DEBUG_WIFI     
  Serial.println("Starting connection to server...");
#endif  

  if (client.connect(SERVER_NAME, SERVER_PORT)) {
#ifdef DEBUG_WIFI     
    Serial.println("Connected to server");
#endif   
  }
  else
  {
#ifdef DEBUG_WIFI      
     Serial.println("server connection failure");
#endif    
  } 
}
void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

J1C.exe
3.04MB

이건 서버 한번만들어주자

저거 해서 포트 만들어주고

내컴터 주소 처주고

열어주고

시작하면

음 잘감 ㅋㅋ

 

받는것도 해보자

  while (Serial.available()) {    //available 수신 값이 있어야 시작한다 아니면 실행 안함
    char c = Serial.read();
    client.write(c);
  }

ㅊ추가하면 보내기도 된다

블로그 이미지

Or71nH

,

자 그럼 스타트는 라즈베리파이를 먼져 열고 시작해 보겠습니다.

 

푸티를 열어주고

 


잘됫으

 

 

아두이노 설치부터 해야됨

 

  $ sudo apt-get install arduino

끗!!

  $ sudo usermod -a -G tty pi

  $ sudo usermod -a -G dialout pi

 

똭 써주고

뭔가 됫음 근뭔지는 모름 일단 됫음

그리고 파일하나 만들자

 

/*
 Pi_Serial_test.cpp - SerialProtocol library - demo
 Copyright (c) 2014 NicoHood.  All right reserved.
 Program to test serial communication
 
 Compile with:
 sudo gcc -o Pi_Serial_Test.o Pi_Serial_Test.cpp -lwiringPi -DRaspberryPi -pedantic -Wall
 sudo ./Pi_Serial_Test.o
 */
 
// just that the Arduino IDE doesnt compile these files.
#ifdef RaspberryPi 
 
//include system librarys
#include <stdio.h> //for printf
#include <stdint.h> //uint8_t definitions
#include <stdlib.h> //for exit(int);
#include <string.h> //for errno
#include <errno.h> //error output
 
//wiring Pi
#include <wiringPi.h>
#include <wiringSerial.h>
 
// Find Serial device on Raspberry with ~ls /dev/tty*
// ARDUINO_UNO "/dev/ttyACM0"
// FTDI_PROGRAMMER "/dev/ttyUSB0"
// HARDWARE_UART "/dev/ttyAMA0"
char device[]= "/dev/ttyACM0";
// filedescriptor
int fd;
unsigned long baud = 9600;
unsigned long time=0;
 
//prototypes
int main(void);
void loop(void);
void setup(void);
 
void setup(){
 
  printf("%s \n", "Raspberry Startup!");
  fflush(stdout);
 
  //get filedescriptor
  if ((fd = serialOpen (device, baud)) < 0){
    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    exit(1); //error
  }
 
  //setup GPIO in wiringPi mode
  if (wiringPiSetup () == -1){
    fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
    exit(1); //error
  }
 
}
 
void loop(){
  // Pong every 3 seconds
  if(millis()-time>=3000){
    serialPuts (fd, "Pong!\n");
    // you can also write data from 0-255
    // 65 is in ASCII 'A'
    serialPutchar (fd, 65);
    time=millis();
  }
 
  // read signal
  if(serialDataAvail (fd)){
    char newChar = serialGetchar (fd);
    printf("%c", newChar);
    fflush(stdout);
  }
 
}
 
// main function for normal c++ programs on Raspberry
int main(){
  setup();
  while(1) loop();
  return 0;
}
 
#endif //#ifdef RaspberryPi

 

 

 

미쿡 형이 잘 설명도 써놧음 찬찬 히 읽으면 이해됨

 

나는 시리얼 보드벤드?? baud??? 이거 115200 이라 

바꿔줫음

 

그리고 실행!!

아 

이거 아두이누는 

이렇게 넣어주고

 

#include <DHT.h>
#define DHTTYPE DHT11

int pinGnd = 4;
int pinVcc = 3;
int pinDht = 2;

DHT dht(pinDht, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(pinVcc, OUTPUT);
  pinMode(pinGnd, OUTPUT);
  digitalWrite(pinVcc, HIGH);
  digitalWrite(pinGnd, LOW);

  dht.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
  float fTemp = dht.readTemperature();
  float fHumi = dht.readHumidity();

  if(isnan(fTemp) || isnan(fHumi)) {
    Serial.println("Falled to read from DNT semsor!");
    return;
  }
  Serial.print("Temperature : ");
  Serial.print(fTemp);
  Serial.print("[C]\t ");
  Serial.print("Humidity: ");
  Serial.print(fHumi);
  Serial.print("%\n");    
  }

이거 칩 셋팅은

 

 

이렇게 햇음

 

 

자그럼 작성도 다됫고

 $ dmesg|tail

아두이노 잘 읽히나 잘보고

 

 

$ sudo gcc test.c -o hello -l wiringPi -DRaspberryPi

  $ sudo ./hello

이렇게

잘 만들어주면

습도 보내기 완료!!

좋았스~

 

 

 

 

블로그 이미지

Or71nH

,

됫다

코드

 

int ledPin = 10; //LED가 연결된 아두이노의 디지털 10번(D10)은 "ledpin"으로 정의
int inPin = 7; //디지털 버튼 7
int val;

void setup() {
  // put your setup code here, to run once:
    pinMode(ledPin, OUTPUT); // ledpin(D10)은 출력
    pinMode(inPin,INPUT); // inpin(D7)은 버튼
}

void loop() {
  // put your main code here, to run repeatedly:
    val = digitalRead(inPin); //val 버튼 입력 정의
    if( val == LOW)   //val 버튼 입력이 LOW이면
      digitalWrite(ledPin, LOW);  //LED 꺼짐
    else              // 아니면
      digitalWrite(ledP in, HIGH); //LED 켜짐
}

이제

선을 잘 뽑아준다

이리 만들면됨

번호는 상관없음

세로 줄만 잘맞추면됨

블로그 이미지

Or71nH

,

 

 

이렇게 적어주고

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Hello World");
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("Hello World");
  delay(1000);
}

업로드

 

 

그리고

 

 

저거 누르면

 

 

실행이 된다

 

 

이제 LED 를 만들어보자

브레드 보드를 꺼네준다

10번이 긴거임니다!!!
긴거가 10

 

잘 써주고

 

 

int ledPin = 10; //LED가 연결된 아두이노의 디지털 10번(D10)은 "ledpin"으로 정의
void setup() {
  // put your setup code here, to run once:
    pinMode(ledPin, OUTPUT); // ledpin(D10)은 출력
}

void loop() {
  // put your main code here, to run repeatedly:
    digitalWrite(ledPin,HIGH); //ledpin(D10)에 HIGH의 디지털 출력
    delay(1000);

    digitalWrite(ledPin,LOW); //ledpin(D10)에 LOW의 디지털 츨력
    delay(1000);
}

아두이노 실행해보자

오오옷!!!!

블로그 이미지

Or71nH

,