Engineering and technology notes

DNS on Ubuntu 18.04

For years it’s been simple to set up DNS on a Linux machine. Just add a couple of entries to /etc/resolv.conf and you’re done.

# Use Google's public DNS servers.
nameserver 8.8.4.4
nameserver 8.8.8.8

But things change and now it’s not that simple. If you now edit /etc/resolv.conf on Ubuntu you’ll find that the edits are ephemeral. If you restart (or even hibernate) your machine then they’ll be overwritten by default content.

nameserver 127.0.0.53
search Home

This is pretty simple to fix though.

  1. Install the resolvconf package.
sudo apt install resolvconf
  1. Edit /etc/resolvconf/resolv.conf.d/head and add the following:
# Make edits to /etc/resolvconf/resolv.conf.d/head.
nameserver 8.8.4.4
nameserver 8.8.8.8
  1. Restart the resolvconf service.
sudo service resolvconf restart

Fix should be permanent.

 

Source: DNS on Ubuntu 18.04 – datawookie

Via Panisperna boys

The Via Panisperna boys (Italian: I ragazzi di Via Panisperna) were a group of young scientists led by Enrico Fermi. In Rome in 1934, they made the famous discovery of slow neutrons which later made possible the nuclear reactor, and then the construction of the first atomic bomb.

The nickname of the group comes from the address of the Physics Institute, at the University of Rome La Sapienza. The Via Panisperna, a street of Rione Monti in the city center, got its name from a nearby monastery, San Lorenzo in Panisperna.

The other members of the group were Edoardo AmaldiOscar D’AgostinoEttore MajoranaBruno PontecorvoFranco Rasetti and Emilio Segrè. All of them were physicists, except for D’Agostino who was a chemist.

Source: Via Panisperna boys – Wikipedia

Arduino-Sample-Codes/Sim7600_MQTT.ino

/*
Developed by Nandu, Anandu, Unnikrishnan
Company: Elementz Engineers Guild Pvt Ltd
*/
#include<SoftwareSerial.h>
SoftwareSerial mySerial(3,2);
#define sw 5
#define led 7
int flag = 1;
int flag1 = 0;
int state=0;
String Publish = led/publish; //Publish Topic
String Subscribe = led/subscribe; //Subscribe Topic
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
pinMode(sw, INPUT_PULLUP);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
//AT Commands for setting up the client id and Server
//Need to be executed once — Open serial terminal doe seeing the debug messages
Serial.println(Connecting To Server……..);
mySerial.println(ATE0);
delay(2000);
mySerial.println(AT+CMQTTSTART); //Establishing MQTT Connection
delay(2000);
mySerial.println(AT+CMQTTACCQ=0,\”elementz/123\”); //Client ID – change this for each client as this need to be unique
delay(2000);
mySerial.println(AT+CMQTTCONNECT=0,\”tcp://test.mosquitto.org:1883\”,90,1); //MQTT Server Name for connecting this client
delay(2000);
//SUBSCRIBE MESSAGE
//Need to be executed once
mySerial.println(AT+CMQTTSUBTOPIC=0,9,1); //AT Command for Setting up the Subscribe Topic Name
delay(2000);
mySerial.println(Subscribe); //Topic Name
delay(2000);
mySerial.println(AT+CMQTTSUB=0,4,1,1); //Length of message
delay(2000);
mySerial.println(HAII); //message
delay(2000);
Serial.println(Done);
}
void loop()
{
String a;
if(state==0)
{
if(digitalRead(sw) == 0 && flag1 == 0)
{
//PUBLISH MESSAGE
flag1 = 1;
digitalWrite(led, HIGH);
Serial.println(Publishing Message: LED ON);
mySerial.println(AT+CMQTTTOPIC=0,8); //AT Command for Setting up the Publish Topic Name
delay(1000);
mySerial.println(Publish); //Topic Name
delay(1000);
mySerial.println(AT+CMQTTPAYLOAD=0,1); //Payload length
delay(1000);
mySerial.println(a); //Payload message
delay(1000);
mySerial.println(AT+CMQTTPUB=0,1,60); //Acknowledgment
delay(1000);
}
else if(digitalRead(sw) == 0 && flag1 == 1)
{
flag1 = 0;
digitalWrite(led, LOW);
Serial.println(Publishing Message: LED OFF);
mySerial.println(AT+CMQTTTOPIC=0,8); //AT Command for Setting up the Publish Topic Name
delay(1000);
mySerial.println(Publish); //Topic Name
delay(1000);
mySerial.println(AT+CMQTTPAYLOAD=0,1); //Payload length
delay(1000);
mySerial.println(b); //Payload message
delay(1000);
mySerial.println(AT+CMQTTPUB=0,1,60); //Acknowledgment
delay(1000);
}
}
if(state==1)
{
if(digitalRead(sw) == 0 && flag1 == 0)
{
//PUBLISH MESSAGE
flag1 = 1;
digitalWrite(led, LOW);
Serial.println(Publishing Message: LED OFF);
mySerial.println(AT+CMQTTTOPIC=0,8); //AT Command for Setting up the Publish Topic Name
delay(1000);
mySerial.println(Publish); //Topic Name
delay(1000);
mySerial.println(AT+CMQTTPAYLOAD=0,1); //Payload length
delay(1000);
mySerial.println(b); //Payload message
delay(1000);
mySerial.println(AT+CMQTTPUB=0,1,60); //Acknowledgment
delay(1000);
}
else if(digitalRead(sw) == 0 && flag1 == 1)
{
flag1 = 0;
digitalWrite(led,HIGH);
Serial.println(Publishing Message: LED ON);
mySerial.println(AT+CMQTTTOPIC=0,8); //AT Command for Setting up the Publish Topic Name
delay(1000);
mySerial.println(Publish); //Topic Name
delay(1000);
mySerial.println(AT+CMQTTPAYLOAD=0,1); //Payload length
delay(1000);
mySerial.println(a); //Payload message
delay(1000);
mySerial.println(AT+CMQTTPUB=0,1,60); //Acknowledgment
delay(1000);
}
}
//Receiving MODEM Response
while(mySerial.available()>0)
{
delay(10);
a = mySerial.readString();
if(flag==0)
{
//Serial.println(a);
flag = 1;
}
//Serial.println(b);
if(a.indexOf(PAYLOAD) != –1)
{
flag = 0;
int new1 = a.indexOf(PAYLOAD);
String neww = a.substring(new1);
int new2 = neww.indexOf(\n);
String new3 = neww.substring(new2+1);
int new4 = new3.indexOf(\n);
String new5 = new3.substring(0,new4);
Serial.println(Topic: led/subscribe);
Serial.print(Message is: );
Serial.println(new5);
new5.remove(new5.length()-1);
if(new5 == a)
{
state=1;
Serial.println(LED ON);
digitalWrite(led, HIGH);
}
else if(new5 == b)
{
state=0;
flag1=0;
Serial.println(LED OFF);
digitalWrite(led, LOW);
}
}
}
}

 

Source: Arduino-Sample-Codes/Sim7600_MQTT.ino at master · elementzonline/Arduino-Sample-Codes · GitHub

Waiting for AT COMMAND correct response – Using Arduino

int16_t wait(char* Values, uint16_t timeout) {

uint16_t Length = strlen(Values);

char InputBuffer[Length + 1];
strcpy(InputBuffer, Values);
char CompareBuffer[Length + 1];
memset(CompareBuffer,0,sizeof(CompareBuffer));

uint16_t Quantity = 1;

for (int16_t n = 0; n < Length; n++) {
if (InputBuffer[n] == ‘,’)
Quantity++;
}

char* InputTokens[Quantity];
memset(InputTokens, 0, sizeof(InputTokens));
char* CompareTokens[Quantity];
memset(CompareTokens, 0, sizeof(CompareTokens));

InputTokens[0] = InputBuffer;
CompareTokens[0] = CompareBuffer;

uint16_t TokenPosition = 1;
for (int16_t n = 0; n < Length; n++) {
if (InputBuffer[n] == ‘,’) {
InputBuffer[n] = 0;
InputTokens[TokenPosition] = &InputBuffer[n + 1];
CompareTokens[TokenPosition] = &CompareBuffer[n + 1];
TokenPosition++;
}
}

uint64_t timer = millis();
char c;

while (millis() – timer < timeout) {
while (mySerial.available()) {
c = mySerial.read();
Serial.print(c);

for (int16_t n = 0; n < Quantity; n++) {
Length = strlen(CompareTokens[n]);
if (c == InputTokens[n][Length])
CompareTokens[n][Length] = c;
else
memset(CompareTokens[n], 0, Length);

if (!strcmp(InputTokens[n],CompareTokens[n]))
return n;
}
}
}
return -1;
}

Source: Waiting for AT COMMAND correct response – Using Arduino / Programming Questions – Arduino Forum