낚시웨어러블 제작기

경환오·2021년 10월 28일
0

학교공부

목록 보기
7/8

낚시웨어러블을 만들었다.

레디
2가지 버튼을 통해서 클라우드 서버와 통신하고 GPS를 통해 현재지역의 어종정보를 출력해주고 해당지역에서 물고기를 잡으면 바로바로 클라우드에 저장해 내가 가장 많이 물고기를 낚은 지역을 특징한다.

아두이노를 활용해서 만들었고 오랜만에 C/C++을 활용하니까 재밌었다. 특히 IOT를 만들면서 확실히 IOT가 데이터분석분야에 큰 발전을 불러올 것이라 생각했다.

#include <ESP8266WiFi.h> // ESP 8266 와이파이 라이브러리
#include <ESP8266HTTPClient.h> // HTTP 클라이언트
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <LiquidCrystal_I2C.h>

#define RXPIN D4
#define TXPIN D3
#define GPSBAUD 9600 

#define fish_buuton D6
#define capture_buuton D5

TinyGPS gps;
LiquidCrystal_I2C lcd(0x27,16,2); 
SoftwareSerial uart_gps(TXPIN, RXPIN);

void getgps(TinyGPS &gps);
char *s;
char y[255];
char *result = NULL;
int gps_go_value = 1;

float now_LAT = 36.756988, now_LON = 125.653731;
String Sea_area_value;
int Sea_area_numvalue;
String month;

void printfish() {
  strcpy(y,s);
  result = strtok(y, ", ");
  while(result != NULL) {
    lcd.init();
    String r = "Fish=";
    lcd.print(r+result);
    lcd.setCursor(0,1);
    lcd.print(Sea_area_value);
    delay(200);
    result = strtok(NULL, ", ");
  }
}

char fish[9][12][255] = 
  {{"low season","low season","Low season, flounder", "Low season, flounder, rockfish, noraemi","Flounder, Rockfish, noraemi", "Rockfish, noraemi, sea bass, Conger, flounder, mullet",
  "Rockfish, noraemi, sea bass,Conger, flounder, mullet,Gizzard shad, mackerel, rockfish,Noraemi, sea bass,Conger, flounder, mullet",
  "Gizzard shad, mackerel, rockfish,Noraemi, sea bass,Conger, flounder, mullet,Hakgongchi, mangdungeo", 
  "Gizzard shad, mackerel, rockfish,Noraemi, sea bass,Conger, flounder,mullet,Hakgongchi, mangdungeo",
  "Rockfish, noraemi, mangdungeo","Seasonality, rockfish,emi, mangdungeo"}, 
  
  {"low season","low season", "Low season, flounder", "Low season, flounder,Rockfish, noraemi", "Hakgongchi, black sea bream,Rockfish, noraemi, flounder, mullet, perch, eel, cod", 
  "Hakgongchi, black sea bream,Rockfish, noraemi, flounder,Mullet, sea bass, conger eel,Snapper, cod","Boguchi, parrot fish,Busiri, black sea bream,Rockfish, noraemi, flounder, mullet, perch, eel,Snapper, cod",
  "Boguchi, parrot fish,Busiri, black sea bream,Rockfish, noraemi, flounder,Mullet, sea bass, conger eel,Snapper, mangdungeo,Mackerel, hakgongchi,Gizzard shad, mackerel, cod",
  "Boguchi, parrot fish,Busiri, black sea bream,Rockfish, noraemi, flounder,Mullet, sea bass, conger eel,Jjukkumi, cuttlefish,Mangdungeo, mackerel,Hakgongchi, gizzard shad,Spanish mackerel, cod",
  "Black sea bream, rockfish, noraemi,Flounder, mullet, sea bass,Conger, jjukkumi,Cuttlefish, mangdungeo,Mackerel, hakgongchi, gizzard shad,Spanish mackerel, cod",
  "Rockfish, noraemi, flounder,Mullet, sea bass, conger eel,Mangdungeo", "Seasonality, rockfish, noraemi,Mangdungeo"},
  
  {"Mullet, rockfish, noraemi,Black sea bream, Open", "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Heat", "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Open, flounder, perch", 
  "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Flounder, sea bass, sea bream,conger", "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Flounder, sea bass, sea bream,conger",
  "Mullet, rockfish, noraemi,Bengedom, parrot fish, flounder,Sea bass, sea bream, conger", "Mullet, rockfish, noraemi,Bengedom, parrot fish, flounder,Sea bass, squid, pattern,Sea bream, conger",
  "Mullet, rockfish, noraemi,Bengedom, parrot fish, flounder,Sea bass, squid, pattern,Sea bream, conger eel, mackerel,Pompano, cutlass, hakgongchi",
  "Mullet, rockfish, noraemi,Black sea bream, flounder, perch,Pattern squid, snapper,Conger eel, mackerel,Pompano, cutlass, hakgongchi",
  "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Pattern squid, snapper,Conger eel, mackerel,Pompano, cutlass, hakgongchi","Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream,Gar, hakgongchi"
  "Mullet, rockfish, noraemi,Mangsangeo, rockfish, and black sea bream, hairtail, hakgongchi"},
  
  {"Mullet, noraemi, bengedom,Black sea bream, hakgongchi,Horaegi, rockfish, ssom drunk,Rockfish", "Mullet, noraemi, bengedom,Black sea bream, rockfish, ssom drunk,Rockfish",
  "Mullet, noraemi, bengedom,Black sea bream, flounder, perch,Mangsangeo, rockfish, red snapper,Conger eel, rockfish, ssom drunk,Rockfish",
  "Mullet, noraemi, bengedom,Black sea bream, flounder, perch,Mangsangeo, rockfish, red snapper,Conger eel, rockfish, ssom drunk,Rockfish", "Mullet, noraemi, flounder,Bass, mangsangeo, rockfish,Sea bream, conger eel, bengedom,Borimyeol",
  "Mullet, noraemi, limit values,Flounder, sea bass, sea bream,Conger, bengedom, borimyeol", "Mullet, noraemi, limit values,Flounder, sea bass, parrot fish,Pattern squid, busiri,Sea bream, conger eel, bengedom, borimyeol",
  "Mullet, noraemi, limit values,Flounder, sea bass, parrot fish,Pattern squid, busiri,Sea bream, conger eel, bengedom, borimyeol", 
  "Mullet, noraemi, mackerel,Pompano, cutlass fish, black sea bream,Flounder, sea bass, parrot fish,Pattern squid, busiri,Sea bream, conger eel, bengedom, borimyeol",
  "Mullet, noraemi, mackerel,Pompano, cutlass fish, black sea bream,Flounder, sea bass, parrot fish,Pattern squid, busiri,Sea bream, conger",
  "Mullet, noraemi, mackerel,Pompano, cutlass fish, black sea bream,Flounder, sea bass, parrot fish,Pattern squid, busiri,Sea bream, conger eel, hakgongchi, horaegi","Mullet, noraemi, bengedom,Black sea bream, hakgongchi, horaegi"},
  
  {"Minnows, noraemi, rockfish,Mullet, flounder for salmon juxtaposition, Daegu", "Minnows, noraemi, rockfish,Mullet, flounder, cod for", 
  "Minnows, noraemi, rockfish,Mullet, for flatfish, Atka mackerel, daeguhoetdae, flounder, leg strength, cod", "Minnows, noraemi, rockfish,Mullet, black sea bream, Atka mackerel, daeguhoetdae, flounder, intensity leg",
  "Minnow, noraemi, rockfish, black sea bream, Atka mackerel, daeguhoetdae, flounder, leg strength, conger", "Minnows, noraemi, rockfish, US participants, daeguhoetdae, conger",
  "Minnows, noraemi, rockfish,US participants, daeguhoetdae, conger", "Minnows, noraemi, rockfish,US participants, daeguhoetdae, bengedom, conger",
  "Minnows, noraemi, rockfish,Mullet, black sea bream, US participants, daeguhoetdae, bengedom, mackerel, eel", "Minnows, noraemi, rockfish,Mullet, black sea bream, US participants, hakgongchi, bengedom,The juxtaposition of salmon, mackerel, cod, conger",
  "Minnows, noraemi, rockfish,Mullet, black sea bream, hakgongchi,Sandfish, juxtaposed salmon, cod", "Minnows, noraemi, rockfish,Mullet, sandfish, juxtaposed salmon, cod"},
  
  {"Bengedom, minnows, noraemi,Rockfish, flounder, hakgongchi,Rockfish, cod, open, perch", "Bengedom, minnows, noraemi,Rockfish, flounder, Atka mackerel, mangsangeo, hakgongchi,Leg strength, rockfish, yellow rockfish, hwangjeom rockfish, cod, open the East limit values",
  "Bengedom, minnows, noraemi,Rockfish, flounder, Atka mackerel, black sea bream, helicolenus hilgendorfii eyes boldae,Mangsangeo, hakgongchi, flounder, leg strength, rockfish, yellow rockfish, hwangjeom rockfish, cod, open the East limit values",
  "Bengedom, minnows, noraemi,Rockfish, flounder, Atka mackerel, black sea bream, helicolenus hilgendorfii eyes boldae, mangsangeo, flounder, leg strength, and indeed rockfish, rockfish, yellow rockfish, rockfish hwangjeom Donghae limit values",
  "Bengedom, minnows, noraemi,Rockfish, flounder, helicolenus hilgendorfii,Boldae eyes, flounder, leg strength, and indeed rockfish, rockfish, yellow rockfish, hwangjeom rockfish, sea bass, the East limit values",
  "Bengedom, minnows, noraemi,Rockfish, flounder, borimyeol,Busiri, flounder, leg strength, indeed rockfish, rockfish,Yellow rockfish, rockfish hwangjeom, perch, gar",
  "Bengedom, minnows, noraemi,Rockfish, flounder, borimyeol,Busiri, leg strength,Indeed rockfish, yellow rockfish, perch, gar",
  "Bengedom, minnows, noraemi,Rockfish, flounder, borimyeol,Busiri, Spanish mackerel, mackerel,Indeed rockfish, yellow rockfish, open, perch, gar",
  "Bengedom, minnows, noraemi,Rockfish, flounder, borimyeol,Black sea bream, busiri, Spanish mackerel,Mackerel, flounder, rockfish indeed, yellow rockfish, pattern, squid, cod, open, perch, gar",
  "Bengedom, minnows, noraemi,Rockfish, flounder, black sea bream,Busiri, Spanish mackerel, mackerel,Flounder, rockfish true,Yellow rockfish, pattern, squid, cod, open, perch, gar",
  "Bengedom, minnows, noraemi,Rockfish, flounder, black sea bream,Busiri, Spanish mackerel, mackerel,Hakgongchi, indeed rockfish, rockfish,Pattern squid, cod, open, perch, gar"},
  
  {"Pattern squid, mullet,Bengedom, halibut perch,Bass, black sea bream, hakgongchi, galjeongaengyi", "Pattern squid, mullet,Bengedom, black sea bream, hakgongchi",
  "Pattern squid, mullet,Bengedom, flounder sea bass, black sea bream", "Pattern squid, mullet,Bengedom, flounder sea bass, parrot fish",
  "Pattern squid, mullet,Bengedom, flounder sea bass, parrot fish, sea bream, benjari, jaridom, dokgasichi", "Pattern squid, mullet,Bengedom, flounder sea bass, parrot fish, sea bream, benjari, borimyeol, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, limit values, horse mackerel, mackerel, parrot fish, barracuda, red snapper, benjari, borimyeol, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, limit values, horse mackerel, mackerel, parrot fish, dageumbari, barracuda, benjari, borimyeol, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, limit values, horse mackerel, mackerel, parrot fish, dageumbari, barracuda, benjari, borimyeol, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, horse mackerel, mackerel, parrot fish, dageumbari, barracuda, busiri, galjeongaengyi, borimyeol, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, flounder sea bass, sea bass, black sea bream, dageumbari, busiri, galjeongaengyi, jaridom, dokgasichi, gar",
  "Pattern squid, mullet,Bengedom, flounder sea bass, sea bass, black sea bream, busiri, galjeongaengyi, dokgasichi, gar"},
  
  {"low season", "low season", "low season", "low season", "Rockfish open snapper", "Rockfish, open, red snapper,Bengedom, busiri",
  "Rockfish, open, red snapper,Bengedom, busiri", "Rockfish, open, red snapper,Bengedom, busiri", "Rockfish, open, red snapper,Bengedom, busiri",
  "Rockfish, open, red snapper,Bengedom, busiri", "Rockfish, open, red snapper,Busiri", "Seasonality, red snapper, busiri"},
  
  {"INLAND", "INLAND","INLAND","INLAND","INLAND","INLAND","INLAND","INLAND","INLAND","INLAND","INLAND","INLAND"}};

void Cloud_transmission_input_location(){ //현제 위치값 클라우드에 전송
  WiFiClient client; // 와이파이 클라이언트 객체
  HTTPClient http; // HTTP 클라이언트 객체
  String url = "http://api.thingspeak.com/update?api_key=UYLW7IJ32RINY8LM&field1="+String(now_LAT,6)+"&field2="+String(now_LON,6);
  if (http.begin(client, url)) {  // HTTP
      // 서버에 연결하고 HTTP 헤더 전송
      int httpCode = http.GET();

      // httpCode 가 음수라면 에러
      if (httpCode > 0) { // 에러가 없는 경우
          String payload = http.getString(); // 받은 XML 데이터를 String에 저장
          Serial.println(payload);
      } else {
        Serial.printf("[HTTP] GET... 실패, 에러코드: %s\n", http.errorToString(httpCode).c_str());
      }
      http.end();
      } else {
      Serial.printf("[HTTP] 접속 불가\n");
    }
}

void Cloud_transmission_input_month(){ //현제 월 클라우드에서 받아오기
  WiFiClient client; // 와이파이 클라이언트 객체
  HTTPClient http; // HTTP 클라이언트 객체
  String url = "http://api.thingspeak.com/channels/1392738/feeds.json?results=1";
  if (http.begin(client, url)) {  // HTTP
      // 서버에 연결하고 HTTP 헤더 전송
      int httpCode = http.GET();

      // httpCode 가 음수라면 에러
      if (httpCode > 0) { // 에러가 없는 경우
          String payload = http.getString(); // 받은 XML 데이터를 String에 저장
          int first = payload.indexOf("-");
          int second = payload.indexOf("-",first+1);
          month = payload.substring(first+1, second);
          Serial.println();
          Serial.println(payload);
          Serial.print("월 : ");
          Serial.println(month);
      } else {
        Serial.printf("[HTTP] GET... 실패, 에러코드: %s\n", http.errorToString(httpCode).c_str());
      }
      http.end();
      } else {
      Serial.printf("[HTTP] 접속 불가\n");
    }
}

void Cloud_transmission_input_capture(){ //현제 포획 클라우드에 전송
  WiFiClient client; // 와이파이 클라이언트 객체
  HTTPClient http; // HTTP 클라이언트 객체
  String url = "http://api.thingspeak.com/update?api_key=60O4LCWVU0SPEOE0&field"+String(Sea_area_numvalue)+"=1";
  if (http.begin(client, url)) {  // HTTP
      // 서버에 연결하고 HTTP 헤더 전송
      int httpCode = http.GET();

      // httpCode 가 음수라면 에러
      if (httpCode > 0) { // 에러가 없는 경우
          String payload = http.getString(); // 받은 XML 데이터를 String에 저장
          Serial.println(payload);
          lcd.init();
          String text = "-CP:"+payload;
          lcd.print(text);
          lcd.setCursor(0,1);
          lcd.print(Sea_area_value);
      } else {
        Serial.printf("[HTTP] GET... 실패, 에러코드: %s\n", http.errorToString(httpCode).c_str());
      }
      http.end();
      } else {
      Serial.printf("[HTTP] 접속 불가\n");
    }
}

void Sea_area(){
  
  if ((now_LAT>36.756987) && (now_LAT<37.773376) && (now_LON>125.653730) && (now_LON<126.973542)) {
    Sea_area_value = "West_North_Sea";
    Sea_area_numvalue = 1;
  }
  else if ((now_LAT>34.773811) && (now_LAT<36.756986) && (now_LON>125.653730) && (now_LON<126.973542)) {
    Sea_area_value = "West_South_Sea";
    Sea_area_numvalue = 2;
  }
  else if ((now_LAT>34.053622) && (now_LAT<34.773810) && (now_LON>126.973542) && (now_LON<127.634060)) {
    Sea_area_value = "South_West_Sea";
    Sea_area_numvalue = 3;
  }
  else if ((now_LAT>34.053622) && (now_LAT<35.437004) && (now_LON>127.634061) && (now_LON<129.679337)) {
    Sea_area_value = "South_East_Sea";
    Sea_area_numvalue = 4;
  }
  else if ((now_LAT>36.770101) && (now_LAT<38.609454) && (now_LON>128.128108) && (now_LON<129.679337)) {
    Sea_area_value = "East_North_Sea";
    Sea_area_numvalue = 5;
  }
  else if ((now_LAT>35.437005) && (now_LAT<36.770100) && (now_LON>129.052743) && (now_LON<129.679337)) {
    Sea_area_value = "East_South_Sea";
    Sea_area_numvalue = 6;
  }
  else if ((now_LAT>33.030691) && (now_LAT<33.631961) && (now_LON>125.986793) && (now_LON<127.066273)) {
    Sea_area_value = "Jeju_Chuja";
    Sea_area_numvalue = 7;
  }
  else if ((now_LAT>37.409910) && (now_LAT<37.572536) && (now_LON>130.723668) && (now_LON<131.004961)) {
    Sea_area_value = "Ulleungdo";
    Sea_area_numvalue = 8;
  }
  else {
    Sea_area_value = "Inland";
    Sea_area_numvalue = 9;
  }
}

void getgps(TinyGPS &gps)
{
  float latitude, longitude;  //, 경도
  gps.f_get_position(&latitude, &longitude);
  Serial.print("위도 : "); 
  Serial.println(latitude,5); 
  Serial.print("경도 : "); 
  Serial.println(longitude,5);
  now_LAT = latitude;
  now_LON = longitude;
  delay(1000);
}

void gps_go(){
  while(uart_gps.available())     // While there is data on the RX pin...
  {
      int c = uart_gps.read();    // load the data into a variable...
      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps);         // then grab the data.
        Serial.println('.');
        gps_go_value = 0;
        lcd.init();
        lcd.print("Ready");
      }  
  }
}


void setup()
{
  pinMode(fish_buuton, INPUT_PULLUP);
  pinMode(capture_buuton, INPUT_PULLUP);
  // 시리얼 세팅
  Serial.begin(115200);
  Serial.println();
  uart_gps.begin(GPSBAUD);

  // 와이파이 접속
  WiFi.begin("204", "5317797q"); // 공유기 이름과 비밀번호

  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) // 와이파이 접속하는 동안 "." 출력
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected, IP address: ");
  Serial.println(WiFi.localIP()); // 접속된 와이파이 주소 출력
  lcd.begin(16,2);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
}

void loop() {
  int cnt = 0;
  String Login = "Loding";
  /*while(gps_go_value){
    lcd.init();
    lcd.print(Login);
    gps_go();
    Login += ".";
    cnt++;
    if(cnt>5){
      cnt = 0;
      Login = "Loding";
    }
    delay(1000);
  }*/
  if (WiFi.status() == WL_CONNECTED){
    if(digitalRead(fish_buuton)==0){
      Cloud_transmission_input_location();
      Cloud_transmission_input_month();
      Sea_area();
      s = fish[Sea_area_numvalue-1][month.toInt()-1];
      Serial.print(s);
      printfish();
    }
    if(digitalRead(capture_buuton)==0){
    Cloud_transmission_input_capture();
    lcd.setCursor(0,1);
    lcd.print(Sea_area_value);
    }
    
  }
  delay(100);
}
profile
방문해주셔서 감사합니다!

0개의 댓글