Samstag, 14. Mai 2016

NRF24L01+ USB Adapter UART Adapter

Abstract

I buyed this Modul because I tried different Communication Systems. In this Post I try to collect the informations about it, because documentation is very  low.

Parameters and commands:


1. The number of bytes in a single transmission valid: 1-31 bytes.
The first 0 byte system reserved for each transmitted packet length statistics; for example serial port to send "123" (ASCII code, 3 bytes), the actual transfer when the first byte 0 to 3, the receiving end of the actual should be handled to determine the packet length byte received under this number.
 
2. Module Baud Rate: 4800,9600,14400,19200,38400,57600,115200.
Covers common baud rate, (factory default 9600)
Baud rate modification command: send ASCII code [AT + BAUD = x] (x is 1,2,3,4,5,6,7 4800,9600,14400,19200,38400,57600,115200 the corresponding baud)

Such as: Modify the baud rate to 115200, the serial debugging assistant sending ASCII [AT + BAUD = 7], the system replies:
Baud rate setting success !!
Baud Rate: 115200
At this baud rate of 115200, serial debugging assistant need to switch to 115 200 to communicate with the module.
Note: The command must be in uppercase letters!

3.NRF24L01 module transmission rate: 1Mbps, 2Mbps (factory default 1Mbps)

Transmission rate setting command: send ASCII code [AT + RATE = x] (x 1,2 respectively 1Mbps, the transmission rate of 2Mbps)

Such as: modify the transmission rate of 2Mbps, then sending ASCII serial debugging assistant [AT + RATE = 2], the system replies:
Transmission rate setting success !!

Transmit power: 0dBm
Transfer rate: 2Mbps
Low-noise amplifier gain: open

4, NRF24L01 module address setting: 5 address, local address and the receiver address matches 0 (factory default 0xFF, 0xFF, 0xFF, 0xFF, 0xFF)

Address Set command: Send ASCII code [AT + ADD = 0x ??, 0x ??, 0x ??, 0x ??, 0x ??] (0x ?? address you want to set a comma, the comma must be in English half-width )

Such as: change the address for 0x11,0x22,0x33,0x44,0x55, then sending ASCII serial debugging assistant [AT + ADD = 0x11,0x22,0x33,0x44,0x55], the system replies:

Address Setting Success !!

Local Address: 0x11,0x22,0x33,0x44,0x55
Receiving end address 0: 0x11,0x22,0x33,0x44,0x55

5, System Information inquiry:
Query: sending ASCII [AT?], The system replies:

AT?
System Information:
Baud Rate: 115200
Local Address: 0x11,0x22,0x33,0x44,0x55
Receiving end address 0: 0x11,0x22,0x33,0x44,0x55
Transmit power: 0dBm
Transfer rate: 2Mbps
Low-noise amplifier gain: open

Donnerstag, 5. Mai 2016

Testing ESPDuino

Testing ESPDuino 


I found a Firmware for my ESP8266, Espduino and It sound that this is what I looked for.

    https://github.com/tuanpmt/espduino

Espduino is a library that use the ESP8266 only for communication, It has 2 parts. The EPS8266 Firmware and the Arduino Library which allows you to use MQTT and WIFI.

Internally the library use SLIP to communicate with the ESP8266.

Goal of my project is to use MQTT via WIFI together with a Arduino Board of course on a very cheap basis.


Download Software

    git clone https://github.com/tuanpmt/espduino
    cd espduino

Flashing

First I did is to connect the ESP8266-01 via a FTDI232 to the USB Port.
With the esptool.py Tool it was easy to flash the Firmware to the ESP.
Remember to connect GPIO 0 to GND before Flashing and the power the ESP8266.

esp8266/tools/esptool.py -p /dev/ttyUSB0 write_flash 0x00000 esp8266/release/0x00000.bin 0x40000 esp8266/release/0x40000.bin

Test

My first try was to use an UNO together with Software Serial where the ESP was connected.
This failed! Many parallels Messages bring the System to crash.
I started 5 Publishers with send 1 Message per second. After around 5 Minutes it hangs.
So I use a Ardurino MEGA with more Serial Ports and this worked.

The  Sketch

 
#include <espduino.h>
#include <mqtt.h>



ESP esp(&Serial1, &Serial, 4);
MQTT mqtt(&esp);
boolean wifiConnected = false;

int i=0;

void wifiCb(void* response)
{
  uint32_t status;
  RESPONSE res(response);

  if(res.getArgc() == 1) {
    res.popArgs((uint8_t*)&status, 4);
    if(status == STATION_GOT_IP) {
      Serial.println("WIFI CONNECTED");
      mqtt.connect("192.168.1.50", 1883, false);
      wifiConnected = true;
      //or mqtt.connect("host", 1883); /*without security ssl*/
    } else {
      wifiConnected = false;
      mqtt.disconnect();
    }
    
  }
}

void mqttConnected(void* response)
{
  Serial.println("Connected");
  mqtt.subscribe("/test"); //or mqtt.subscribe("topic"); /*with qos = 0*/

  mqtt.publish("/test1", "AAAAAAAAAAAAAAAAAAAAa");

}
void mqttDisconnected(void* response)
{
  Serial.println("Disconnect");
}
void mqttData(void* response)
{
  RESPONSE res(response);

  Serial.print("Received: topic=");
  String topic = res.popString();
  Serial.println(topic);

  Serial.print("data=");
  String data = res.popString();
  Serial.println(data);

}
void mqttPublished(void* response)
{

}
void setup() {
  Serial1.begin(19200);

  Serial.begin(19200);

  esp.enable();
  delay(500);
  esp.reset();
  delay(500);

  while(!esp.ready()){
    Serial.println(".");
    delay(500);
  }

  Serial.println("ARDUINO: setup mqtt client");
  if(!mqtt.begin("MQTT_HOST", "MQTT_USER", "MQTT_PASSWORD", 120, 1)) {
    Serial.println("ARDUINO: fail to setup mqtt");
    while(1);
  }


  Serial.println("ARDUINO: setup mqtt lwt");
  mqtt.lwt("/lwt", "offline", 0, 0); 

/*setup mqtt events */
  mqtt.connectedCb.attach(&mqttConnected);
  mqtt.disconnectedCb.attach(&mqttDisconnected);
  mqtt.publishedCb.attach(&mqttPublished);
  mqtt.dataCb.attach(&mqttData);

  /*setup wifi*/
  Serial.println("ARDUINO: setup wifi");
  esp.wifiCb.attach(&wifiCb);

  esp.wifiConnect("WIFI_STATION_ID","WIFI_PASSWORD");


  Serial.println("ARDUINO: system started");
}

void loop() {
  esp.process();
  if(wifiConnected) {


  }
}

Freitag, 8. April 2016

Free GeoTrust SSL Certificates

Free GeoTrust  SSL Certificates


InterNetX the Company where I work offer free GEOTrusts SSL Certificates, if you manage the Domains over them, You can easily manage your Certs with the SSL Manager GUI or also via API.

Important:
- Domains must be managed in your AutoDNS Account
- only 9 subdomains are free, www is included
- OCSP Stapling must be activated on your server, its also better for Performance
- Authentication is done via DNS


Generate an privatekey and cert

openssl req -nodes -new -newkey rsa:2048 -sha256 -out csr.pem


Via API you must perform following steps.



 Get CNAME Information


Request:

<?xml version="1.0" encoding="UTF-8"?>
<request>
<task>
 <code>400110</code>
 <certificate_request>
  <plain><![CDATA[-----BEGIN CERTIFICATE REQUEST-----
MIICyzCCAbMCAQAwgYUxCzAJBgNVBAYTAkRFMQswCQYDVQQIEwJCWTETMBEGA1UE
BxMKUmVnZW5zYnVyZzEPMA0GA1UEChMGbm9uYW1lMQ8wDQYDVQQLEwZzZXJ2ZXIx
FDASBgNVBAMTC2V4YW1wbGUuY29tMRwwGgYJKoZIhvcNAQkBFg14QGV4YW1wbGUu
Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Oh/pN0/DyMFIbe3
5uX08wFrMiOsMKXwOYUhtPdToQAGtXovhP3xihHOMbE8mjenkksqcMO08Smgwsz+
s96AQdo241pF3BN4RzqUEBhFD3eXFW/oKm/3QZq0oTRSe749OK4+ZxxGZ8KwbO14
9RUTOEHnmX63Ji5MEiWGAIpFX84B/9mioCRu2oB22rWT9OtMwugAeSNoyDIE1KIH
ZBLeBnomIFGAEspFcGARMcXKV1NHraRGsDXx87NCBGVQhXW/dAUIWD6D1A1SA+u4
A2Uma4GTwtqzxWnB3ISKIvJ+eNbuh1pwV+RU8jNXP+gTPVB4GL5pqmlDJllYNR+B
AOcfqwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAHCWmgQoYlZp1y10aPbk7P11
/4I62ocrzeBiDp7/DkOAzSaChjzjnmBQo3aeWFa8tFsKQ4M4KtYROVrw05Qfu90i
GLySnfZEcGYb7bzJDF1ZHgivD5DrmU9kZrgRnxungdk13NBkW5oBZfIfpTw1PYrH
y6YDB72to21MCnxepU3rPD6N1CX9RIrbH4RSmL2ARvjhtpGHiHirguppvEk/kmXJ
JtUkVvd9xSKP+BYo2wTOxBq3gTpWNSvtHDH2+w6gNolrk9quwg25re/3YGJOqC+o
uEJUInV2NmzhCK3RaspCDK9utnw6sECgNZ+mjaV0NtdWc1sg9IQEZ6zzkLEftds=
-----END CERTIFICATE REQUEST-----
  ]]></plain>
  <product>BASIC_SSL</product>
 </certificate_request>
</task>
  <auth>
    <user>user</user>
    <password>password</password>
    <context>9</context>
  </auth>
</request> 
 
Response:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<response>
  <result>
    <data>
      <certificate_request>
        <plain><![CDATA[-----BEGIN CERTIFICATE REQUEST-----
        MIICyzCCAbMCAQAwgYUxCzAJBgNVBAYTAkRFMQswCQYDVQQIEwJCWTETMBEGA1UE
        BxMKUmVnZW5zYnVyZzEPMA0GA1UEChMGbm9uYW1lMQ8wDQYDVQQLEwZzZXJ2ZXIx
        FDASBgNVBAMTC2V4YW1wbGUuY29tMRwwGgYJKoZIhvcNAQkBFg14QGV4YW1wbGUu
        Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Oh/pN0/DyMFIbe3
        5uX08wFrMiOsMKXwOYUhtPdToQAGtXovhP3xihHOMbE8mjenkksqcMO08Smgwsz+
        s96AQdo241pF3BN4RzqUEBhFD3eXFW/oKm/3QZq0oTRSe749OK4+ZxxGZ8KwbO14
        9RUTOEHnmX63Ji5MEiWGAIpFX84B/9mioCRu2oB22rWT9OtMwugAeSNoyDIE1KIH
        ZBLeBnomIFGAEspFcGARMcXKV1NHraRGsDXx87NCBGVQhXW/dAUIWD6D1A1SA+u4
        A2Uma4GTwtqzxWnB3ISKIvJ+eNbuh1pwV+RU8jNXP+gTPVB4GL5pqmlDJllYNR+B
        AOcfqwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAHCWmgQoYlZp1y10aPbk7P11
        /4I62ocrzeBiDp7/DkOAzSaChjzjnmBQo3aeWFa8tFsKQ4M4KtYROVrw05Qfu90i
        GLySnfZEcGYb7bzJDF1ZHgivD5DrmU9kZrgRnxungdk13NBkW5oBZfIfpTw1PYrH
        y6YDB72to21MCnxepU3rPD6N1CX9RIrbH4RSmL2ARvjhtpGHiHirguppvEk/kmXJ
        JtUkVvd9xSKP+BYo2wTOxBq3gTpWNSvtHDH2+w6gNolrk9quwg25re/3YGJOqC+o
        uEJUInV2NmzhCK3RaspCDK9utnw6sECgNZ+mjaV0NtdWc1sg9IQEZ6zzkLEftds=
        -----END CERTIFICATE REQUEST-----]]></plain>
        <name><![CDATA[example.com]]></name>
        <key_size>2048</key_size>
        <country_code>DE</country_code>
        <product>BASIC_SSL</product>
        <authentication>
          <method>DNS</method>
          <dns>sckyodyje7ev4eltur3wmhyk92yx0hsr.example.com. 300 IN CNAME s20160408170238.example.com.</dns>
        </authentication>
      </certificate_request>
    </data>
    <status>
      <code>S400110</code>
      <text>CSR-Schlüssel wurde erfolgreich geprüft.</text>
      <type>success</type>
    </status>
  </result>
  <stid>20160408-app3-dev-3424</stid>
</response>

Order Certificate

 Request:

<?xml version="1.0" encoding="UTF-8"?>
<request>
  <task>
    <certificate>
      <product>BASIC_SSL</product>
      <lifetime>12</lifetime>
      <software>APACHE2</software>
      <csr><![CDATA[-----BEGIN CERTIFICATE REQUEST-----
MIICyzCCAbMCAQAwgYUxCzAJBgNVBAYTAkRFMQswCQYDVQQIEwJCWTETMBEGA1UE
BxMKUmVnZW5zYnVyZzEPMA0GA1UEChMGbm9uYW1lMQ8wDQYDVQQLEwZzZXJ2ZXIx
FDASBgNVBAMTC2V4YW1wbGUuY29tMRwwGgYJKoZIhvcNAQkBFg14QGV4YW1wbGUu
Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Oh/pN0/DyMFIbe3
5uX08wFrMiOsMKXwOYUhtPdToQAGtXovhP3xihHOMbE8mjenkksqcMO08Smgwsz+
s96AQdo241pF3BN4RzqUEBhFD3eXFW/oKm/3QZq0oTRSe749OK4+ZxxGZ8KwbO14
9RUTOEHnmX63Ji5MEiWGAIpFX84B/9mioCRu2oB22rWT9OtMwugAeSNoyDIE1KIH
ZBLeBnomIFGAEspFcGARMcXKV1NHraRGsDXx87NCBGVQhXW/dAUIWD6D1A1SA+u4
A2Uma4GTwtqzxWnB3ISKIvJ+eNbuh1pwV+RU8jNXP+gTPVB4GL5pqmlDJllYNR+B
AOcfqwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAHCWmgQoYlZp1y10aPbk7P11
/4I62ocrzeBiDp7/DkOAzSaChjzjnmBQo3aeWFa8tFsKQ4M4KtYROVrw05Qfu90i
GLySnfZEcGYb7bzJDF1ZHgivD5DrmU9kZrgRnxungdk13NBkW5oBZfIfpTw1PYrH
y6YDB72to21MCnxepU3rPD6N1CX9RIrbH4RSmL2ARvjhtpGHiHirguppvEk/kmXJ
JtUkVvd9xSKP+BYo2wTOxBq3gTpWNSvtHDH2+w6gNolrk9quwg25re/3YGJOqC+o
uEJUInV2NmzhCK3RaspCDK9utnw6sECgNZ+mjaV0NtdWc1sg9IQEZ6zzkLEftds=
-----END CERTIFICATE REQUEST-----]]></csr>
      <id />
      <name><![CDATA[example.com]]></name>
      <comment />
      <admin>
        <id>1234</id>
      </admin>
      <technical>
        <id>1234</id>
      </technical>
      <auth_method>DNS</auth_method>
    </certificate>
    <ctid />
    <reply_to>someone@example.com</reply_to>
    <code>400101</code>
  </task>
  <auth>
    <user>user</user>
    <password>password</password>
    <context>9</context>
  </auth>
</request>

Montag, 26. Januar 2015

ESP8266 Pinout

ESP8266 Pinouts

ESP8266-12
ESP8266-12



ESP8266-01 Pinout
ESP8266-01

Wichtig beim ESP8266-01 ist das man CH_PD mit VCC verbinden muss.


ESP8266-05 Pinout
ESP8266-05


ESP8266-01 mit NodeMCU (LUA Firmware)

Nach einigen Fehlschlägen mit meinem Arduino und ESP8266 habe ich mich entschlossen das Konzept umzuändern.
Zuerst wollte ich den ESP nur als Wifi Modul nutzen und dem Arduino die Kontrolle übernehmen lassen. Das Problem das ich hatte war das die Serielleverbindung immer Probleme machte. Es ich vermute stark das die BAUD die bei fast allen Firmwares auf 115200 Baud war die Probleme verursachte.

Da ich jetzt  einen FTDI (USB TTL Adapter) bekommen hatte, konnte ich endlich auch die Firmware upgraden. Das Cloud Update ging mit der Version noch nicht.

Mit dem FTDI hatte ich auch keine Probleme mehr mit der Baudrate und der ESP lief ganz stabil. Trotzdem habe ich das teil geflashed jedoch die BAUD Rate konnte ich immer noch nicht einstellen.

Parallel darauf bin ich jedoch auf eine LUA Firmware gestoßen NodeMCU die auch sehr interessant klingt und auch meine bedenken bezüglich WebServer und Arduino zerstreuen.

Neues Ziel ist den Arduino einfach nur als Slave zu dem ESP zu nutzen und Kommandos per Serial Konsole weiterzugeben. Vorteilhaft an dem NodeMCU ist auch das es mit 9600 Baud arbeitet.


NodeMCU - https://github.com/nodemcu/nodemcu-firmware
ESP Tool zum Flashen - https://github.com/themadinventor/esptool


Kommando zum Flashen:

sudo ./esptool.py --port /dev/ttyUSB0 write_flash 0x000000 ../nodemcu-firmware/pre_build/latest/nodemcu_latest.bin

Wichtig ist das GPIO-0 mit GND verbunden ist. Auch musste ich hin und wieder das Teil reseten, weil es zu "Failed to connect" Fehlern gekommen ist.

Ein kleines Script zum Verbinden

> print(wifi.sta.getip())
nil

> wifi.setmode(wifi.STATION)
> wifi.sta.config("SSID","password")
> print(wifi.sta.getip())

192.168.1.112

Sieht soweit alles ganz gut aus :)

Samstag, 20. Dezember 2014

Linux Mint 16 nach 17 Update

Ich hatte einige Rechner mit Linux Mint / XFCE installiert. Nachdem jetzt das 17er raus gekommen ist, hatte ich sie der Reihe nach geupgraded. Ich habe hier eine kurze Anleitung zusammen geschrieben.

Sichern der alten sources.lists:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp /etc/apt/sources.list.d/official-package-repositories.list /etc/apt/sources.list.d/official-package-repositories.list.bak

Umschreiben auf die neuen URLs, das geht einfach mit den SED Befehl

sudo sed -i 's/saucy/trusty/' /etc/apt/sources.list
sudo sed -i 's/petra/qiana/' /etc/apt/sources.list
sudo sed -i 's/saucy/trusty/' /etc/apt/sources.list.d/official-package-repositories.list
sudo sed -i 's/petra/qiana/' /etc/apt/sources.list.d/official-package-repositories.list 
sudo sed -i 's/saucy/trusty/' /etc/apt/sources.list.d/official-source-repositories.list
sudo sed -i 's/petra/qiana/' /etc/apt/sources.list.d/official-source-repositories.list
sudo sed -i 's/saucy/trusty/' /etc/apt/sources.list.d/getdeb.list
sudo sed -i 's/petra/qiana/' /etc/apt/sources.list.d/getdeb.list

Ausführen des eigentlichen Upgrades

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get upgrade


Es gab aber nachdem Upgrade immer die selben 2 Probleme.
Das Networkmanager Applet für WLAN und auch der Lautstärkeregler sind nicht mehr sichtbar.
Die Lösung ist jedoch ganz einfach:
Der Networkmanager muss nur anders gestartet werden, dieses kann man mit einem kleinen Befehl automatisch fixen.

sudo sed -i 's/Exec=nm-applet/Exec=dbus-launch nm-applet/g' /etc/xdg/autostart/nm-applet.desktop

Für den Lautstärkeregler muss man einfach das Packet wieder installieren.

sudo apt-get install xfce4-mixer

Freitag, 16. Mai 2014

Using AutoDNS as PowerDNS Slave Server

If you use AutoDNS as Slave Server you might automatically create and delete zones.

Notifies doesn't work because the Slave Servers did not know your domain. One way to do this is using a MySQL trigger with a simple script.


For example:

CREATE TABLE `domain_events` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `action` varchar(255) NOT NULL default '',
  `status` varchar(255) NOT NULL default '',
  `error_code` varchar(255) NOT NULL default '',
  `created` datetime,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;

DELIMITER $$

CREATE TRIGGER new_domain_created
AFTER INSERT ON `domains` for each row
begin
INSERT INTO domain_events (name,action,status,created)
VALUES (new.name, 'create','pending',now());
END$$

CREATE TRIGGER new_domain_deleted
AFTER DELETE ON `domains` for each row
begin
INSERT INTO domain_events (name,action,status,created)
VALUES (old.name, 'delete','pending',now());
END$$

DELIMITER ; 


On every INSERT/DELETE on the domains-table a corresponding row in the domain-events table is inserted, which can be processed by a simple script.

This script (powerdns-master-sync) can be found here:
https://bitbucket.org/mschrieck/autodns-tools