Jumat, 10 November 2017

mainan NODEMCU modbus

awal beli ini sbnernya ragu.
harganya cuma 50rb an
gogling akhirnya nemu library.
buka toped.
masukkan keraanjang.
pay.
nyampe d rumah..

bingung masukin library???

ikuti tutorial d bwah ini
http://www.instructables.com/id/Programming-ESP8266-ESP-12E-NodeMCU-Using-Arduino-/


jika sudah selesai
download library disini
library modbus tcp nodemcu


coba sketch di=bawah ini :
#include <ESP8266WiFi.h>
#include <ModbusTCPSlave.h>

//WIFI Settings
byte ip[]      = { 192, 168, 1, 187};
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[]  = { 255, 255, 255, 0 };

ModbusTCPSlave Mb;

unsigned long timer;
unsigned long checkRSSIMillis;

void setup()
{

  Mb.begin("nama wifi", "password_wifi", ip, gateway, subnet);

  delay(1000);
  Mb.MBInputRegister[0] = 100;
  Mb.MBInputRegister[1] = 65500;
  Mb.MBInputRegister[2] = 300;
  Mb.MBInputRegister[3] = 400;
  Mb.MBInputRegister[4] = 500;

  Mb.MBHoldingRegister[0] = 1;
  Mb.MBHoldingRegister[1] = 2;
  Mb.MBHoldingRegister[2] = 3;
  Mb.MBHoldingRegister[3] = 4;
  Mb.MBHoldingRegister[4] = 5;

}

void loop()
{
  Mb.Run();
  delay(10);

  if (millis() - timer >= 1000) {
    timer = millis();
    Mb.MBInputRegister[1]++;
  }

  if (millis() - checkRSSIMillis >= 10000) {
    checkRSSIMillis = millis();
    Mb.MBInputRegister[0] = checkRSSI();
  }
}

/*****FUNZIONI*****/

byte checkRSSI() {
  byte quality;
  long rssi = WiFi.RSSI();
  if (rssi <= -100)
    quality = 0;
  else if (rssi >= -50)
    quality = 100;
  else
    rssi = rssi + 100;
  quality = byte(rssi * 2);

  return quality;
}




Tidak ada komentar:

Posting Komentar

Cara membuat datalogger blynk di spreadsheet / googlesheet menggunakan akun versi Free

  silahkan video di atas. semoga bermanfaat. jika masih kurang jelas bisa kontak saya