I want to send a sms using a usb modem through my java application. I tried smslib and i couldn't do my task.
I tried using following code..
I did the external configurations as mentioned also..
So can u please help me on using smslib ina 64bit machine.
package sms;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
public class Sms{
public void doIt() throws Exception
{
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM39", 115200, "Huawei", "");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setSmscNumber("+947100003");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+94755466860", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
Service.getInstance().stopService();
}
public class OutboundNotification implements IOutboundMessageNotification{
public void process(AGateway gateway, OutboundMessage msg){
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
public static void main(String args[]){
Sms app = new Sms();
try{
app.doIt();
}
catch (Exception e){
e.printStackTrace();
}
}
}
I get the following error
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "Thread-3" java.lang.ExceptionInInitializerError
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:69)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:277)
Caused by: java.lang.RuntimeException: CommPortIdentifier class not found
at org.smslib.helper.CommPortIdentifier.<clinit>(CommPortIdentifier.java:76)
... 4 more
Related
I have this code to load CSV data from Cloud Storage into a new BigQuery table. The load operation completes successfully but I need metrics about data count.
import com.google.cloud.bigquery.*;
import com.google.cloud.bigquery.JobInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoadCsvFromGcs {
private static final Logger LOGGER = LoggerFactory.getLogger(LoadCsvFromGcs.class);
private static long csvRowCount;
public static void loadCsvFromGcs(
String datasetName, String tableName, String sourceUri, Schema schema) {
try {
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
CsvOptions csvOptions = CsvOptions.newBuilder().setSkipLeadingRows(1).build();
TableId tableId = TableId.of(datasetName, tableName);
LoadJobConfiguration loadConfig =
LoadJobConfiguration.newBuilder(tableId, sourceUri, csvOptions).setSchema(schema)
.setMaxBadRecords(999999999).build();
Job job = bigquery.create(JobInfo.of(loadConfig));
job = job.waitFor();
csvRowCount = job.getQueryResults().getTotalRows();
LOGGER.info(Long.toString(csvRowCount));
if (job.isDone()) {
LOGGER.info(sourceUri + " CSV from GCS successfully added during load append job");
} else {
LOGGER.error("BigQuery was unable to load into the table due to an error:"
+ job.getStatus().getError() + " , " + sourceUri);
System.exit(-1);
}
} catch (BigQueryException | InterruptedException e) {
LOGGER.error(sourceUri + " Column not added during load append \n" + e);
System.exit(-1);
}
}
}
I took a look at the Google BigQuery documentation and saw that the metrics of the job class can be retrieved with the get functions.
However, when I try, I get the following error.
Exception in thread "main" java.lang.UnsupportedOperationException: Getting query results is supported only for QUERY jobs
How do I find out metrics like how many rows of data are loaded for non-query jobs?
I am trying to implement a simple code to read the data from the ultrasonic and send it to a server by using Californium. The problem is that when I use debug, it doesn't have any error. However when I export the code to a runable jar file and run it on my raspberry pi, it throws the following errors:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/californium/elements/util/NamedThreadFactory
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:163)
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:120)
at iot.main.device.DeviceClient.main(DeviceClient.java:34)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
I am not sure what caused this and how to solve it, any suggestion would be much helpful. Below is the code:
package iot.main.device;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CHANGED;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.eclipse.californium.core.server.resources.CoapExchange;
import com.pi4j.io.gpio.*;
public class DeviceClient {
private static GpioPinDigitalOutput sensorTriggerPin ;
private static GpioPinDigitalInput sensorEchoPin ;
final static GpioController gpio = GpioFactory.getInstance();
public static void main(String[] args) {
double ultraVal;
sensorTriggerPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04); // Trigger pin as OUTPUT
sensorEchoPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_05,PinPullResistance.PULL_DOWN); // Echo pin as INPUT
CoapClient client = new CoapClient("coap://localhost/Ultrasonic");
CoapServer server = new CoapServer();
server.add(new UltraResource());
server.start();
while(true){
try {
Thread.sleep(2000);
sensorTriggerPin.high(); // Make trigger pin HIGH
Thread.sleep((long) 0.00001);// Delay for 10 microseconds
sensorTriggerPin.low(); //Make trigger pin LOW
while(sensorEchoPin.isLow()){ //Wait until the ECHO pin gets HIGH
}
long startTime= System.nanoTime(); // Store the surrent time to calculate ECHO pin HIGH time.
while(sensorEchoPin.isHigh()){ //Wait until the ECHO pin gets LOW
}
long endTime= System.nanoTime(); // Store the echo pin HIGH end time to calculate ECHO pin HIGH time.
ultraVal = ((((endTime - startTime)/1e3)/2) / 29.1);
System.out.println("Distance : " + ultraVal + " cm"); //Printing out the distance in cm
Thread.sleep(1000);
CoapResponse response = client.put(Double.toString(ultraVal), MediaTypeRegistry.TEXT_PLAIN);
if (response!=null) {
System.out.println( response.getCode() );
System.out.println( response.getOptions() );
System.out.println( response.getResponseText() );
} else {
System.out.println("Request failed");
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static class UltraResource extends CoapResource {
public String value = "Resource has not changed yet !!!";
public UltraResource() {
super("Ultrasonic");
setObservable(true);
}
#Override
public void handleGET(CoapExchange exchange) {
exchange.respond(value);
}
#Override
public void handlePUT(CoapExchange exchange) {
String payload = exchange.getRequestText();
System.out.println(payload + " cm");
try {
exchange.respond(CHANGED, payload);
value = new String(payload);
changed();
} catch (Exception e) {
e.printStackTrace();
exchange.respond(BAD_REQUEST, "Invalid String");
}
}
}
}
The error states that
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
This means you are writing code that uses a dependency from Californium. That dependency is within your dev. environment but it is not within the runtime environment of your Raspberry Pi.
Have a look at this other post which may help you. Also this SO site may be better.
My Bukkit plugin command always throws an exception when I run it.
When I type my command: /config set (it should save info to file/config), I get this error in chat:
An internal error occurred while attemping to perform this command.
Why does this happen?
Console Log:
[13:23:24 INFO]: whispereq issued server command: /config set
[13:23:24 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'config' in plugin registyPlayer v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at whispereq.saver.onCommand(saver.java:14) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[src.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
... 13 more
My code from the saver class:
package whispereq;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class saver implements CommandExecutor {
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("config")) {
if (sender instanceof Player) {
if (args.length == 1) {
if (args[1].equalsIgnoreCase("set")) {
sender.sendMessage("§6Registering player§c " + args[0] + "§6 to Server....");
Player p = (Player) sender;
String nick = p.getName().toLowerCase();
String uid = p.getUniqueId().toString();
boolean op = p.isOp();
GameMode gm = p.getGameMode();
GameMode dgm = Bukkit.getDefaultGameMode();
float exp = p.getExp();
float explvl = p.getExpToLevel();
Main.getInst().getConfig().set("players." + nick + ".uuid", uid);
Main.getInst().getConfig().set("players." + nick + ".isOpped", op);
Main.getInst().getConfig().set("players." + nick + ".CurrentGameMode", gm);
Main.getInst().getConfig().set("players." + nick + ".DefaultGameMode", dgm);
Main.getInst().getConfig().set("players." + nick + ".Exp", exp);
Main.getInst().getConfig().set("players." + nick + ".ExpLevel", explvl);
Main.getInst().saveConfig();
sender.sendMessage("§6Finished!, yours Current in-game Status was SUccesfully registered to the config.yml File in Plugin's Directory. use §c/registy getMe§6 to view your Property.");
return true;
} else if (args[1].equalsIgnoreCase("get")) {
Player p = (Player) sender;
String nick = p.getName().toLowerCase();
if (Main.getInst().getConfig().get("players." + nick) != null) {
p.sendMessage("§8_____________________________________________________");
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".uuid"));
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".isOpped"));
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".CurrentGameMode"));
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".DefaultGameMode"));
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + ".Exp"));
p.sendMessage(Main.getInst().getConfig().getString("players." + nick + "ExpLevel"));
p.sendMessage("§8_____________________________________________________");
}
}
}
}
}
return false;
}
}
Main class:
package whispereq;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public static Main instance;
public void onEnable() {
instance = this;
System.out.println("Loading RegistyPlayer ..");
getCommand("config").setExecutor(new saver());
saveDefaultConfig();
}
public static Main getInst() {
return instance;
}
}
Config File (empty):
#-----------------------------------------------------------#
plugin.yml:
name: registyPlayer
version: 1.0
main: whispereq.Main
commands:
config:
Craftbukkit: 1.7.2 R03
Bukkit API: 1.7.2 R03
Server Craftbukkit: 1.7.2 R03
Arrays always start at index 0. Therefore, to access whether the player specified "get" or "set" you should replace
args[1].equalsIgnoreCase("set")
args[1].equalsIgnoreCase("get")
with
args[0].equalsIgnoreCase("set")
args[0].equalsIgnoreCase("get")
Also, not sure what you are doing with the line
sender.sendMessage("§6Registering player§c " + args[0] + "§6 to Server....");
args[0] refers to either "get" or "set". Presumably, you should replace it with "nick" and insert the line after
String nick = p.getName().toLowerCase();
Just wanted to try Cassandra Java driver from eclipse and copied a sample code from "Practical Cassandra"
But faced error below output by eclipse:
Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/util/Timer
at com.datastax.driver.core.Configuration$Builder.build(Configuration.java:294)
at com.datastax.driver.core.Cluster$Builder.getConfiguration(Cluster.java:1247)
at com.datastax.driver.core.Cluster.<init>(Cluster.java:116)
at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:181)
at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1264)
at SampleApp.connect(SampleApp.java:13)
at SampleApp.main(SampleApp.java:64)
Caused by: java.lang.ClassNotFoundException: io.netty.util.Timer
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
here is the sample code:
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
public class SampleApp {
private Cluster cluster;
private Session session;
public void connect(String node) {
cluster = Cluster.builder().addContactPoint(node).build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Cluster: %s\n", metadata.getClusterName());
for ( Host host : metadata.getAllHosts() ) {
System.out.printf("Host: %s \n",host.getAddress());
}
session = cluster.connect();
}
public void close(){
cluster.close();
}
public void createSchema(){
session.execute("CREATE KEYSPACE IF NOT EXISTS portfolio_demo " +
"WITH REPLICATION 5 { ‘class’: ‘SimpleStrategy’, " +
"'replication_factor’: 1 };");
session.execute("CREATE TABLE IF NOT EXISTS portfolio_demo.portfolio (" +
"portfolio_id UUID, ticker TEXT, " +
"current_price DECIMAL, current_change DECIMAL, " +
"current_change_percent FLOAT, " +
"PRIMARY KEY(portfolio_id, ticker));");
}
public void loadData(){
session.execute("INSERT INTO portfolio_demo.portfolio " +
"(portfolio_id, ticker, current_price, " +
" current_change, current_change_percent) VALUES " +
"(756716f7-2e54-4715-9f00-91dcbea6cf50, ‘GOOG’, " +
" 889.07, -4.00, -0.45);");
session.execute("INSERT INTO portfolio_demo.portfolio " +
"(portfolio_id, ticker, current_price, " +
" current_change, current_change_percent) VALUES " +
"(756716f7-2e54-4715-9f00-91dcbea6cf50, ‘AMZN’, " +
" 297.92, -0.94, -0.31);");
}
public void printResults(){
ResultSet results = session.execute("SELECT * FROM " +
"portfolio_demo.portfolio WHERE portfolio_id 5 " +
"756716f7-2e54-4715-9f00-91dcbea6cf50;");
for (Row row : results) {
System.out.println(String.format("%-7s\t%-7s\t%-7s\t%-7s \n%s",
"Ticker", "Price", "Change", "PCT",
"........1........1........1........"));
System.out.println(String.format("%-7s\t%0.2f\t%0.2f\t%0.2f",
row.getString("ticker"),
row.getDecimal("current_price"),
row.getDecimal("current_change"),
row.getFloat("current_change_percent") ));
}
}
public static void main(String[] args) {
SampleApp client = new SampleApp();
client.connect("127.0.0.1");
client.createSchema();
client.loadData();
client.printResults();
client.close();
}
}
And I also added several external JARs which are downloaded or comes with eclipse:
cassandra-driver-core-3.0.0.jar
guava-18.0.jar
netty-3.10.6.Final-20160303.120156-121.jar
org.apache.log4j_1.2.15.v201012070815.jar (from eclipse plugin)
org.slf4j.api_1.7.2.v20121108-1250.jar (from eclipse plugin)
org.slf4j.impl.log4j12_1.7.2.v20131105-2200.jar (from eclipse plugin)
I saw the same questions about the netty error but still could not figure out what was wrong with my code.
Thanks a lot.
This is the wrong Netty version. Version 3.0.0 of the driver uses 4.0.33.
You can view the driver's dependencies in the POM. The properties such as ${netty.version} are defined in the parent POM.
I have done set up a NAS server using NAS4Free and share a folder at:
\\NAS_SERVER_IP/SHARE_FOLDER_NAME
In SHARE_FOLDER_NAME directory contains resource files need to share to multiple clients
Now ,from clients , can I using Java to access (read/write) directly file from NAS server without mount shared folder to local clients
Copied from here, but changed the api call argument.
connecting to shared folder in windows with java
String url = "smb://[NAS server-IP or hostname]/file-or-directory-path";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("[company network domain]", "user", "password");
SmbFile dir = new SmbFile(url, auth);
for (SmbFile f : dir.listFiles())
{
System.out.println(f.getName());
}
For observing file/dir changes using JDK 6, you could use:
WatchService for Java 6
For JDK 7, WatchService is part of NIO package:
http://java.dzone.com/news/how-watch-file-system-changes
Finally, this one works with JDK6 as well. This way, we could observe file/dir changes in windows shared drivers without mounting/mapping them as a drive.
I've used following jars in classpath: commons-collections-4.4.0, commons-logging-1.1.2, commons-logging-api-1.1.2, commons-net-3.3, commons-vfs2-2.0, httpclient-4.3.1, jackrabbit-standalone-2.6.5, jcifs-1.3.17, jsch-0.1.51
import org.apache.commons.vfs2.FileChangeEvent;
import org.apache.commons.vfs2.FileListener;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.impl.DefaultFileMonitor;
public class NFSChangeObserver
{
public static void main(String[] args) throws FileSystemException
{
/** need a non-daemon thread, because <code>DefaultFileMonitor</code> is internally marked as a daemon thread.
*/
Thread t = new Thread(new Runnable() {
#Override
public synchronized void run()
{
try
{
while(1!=2)
wait();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}});
t.start();
FileSystemManager manager = VFS.getManager();
FileObject file = manager.resolveFile("\\\\[server-hostname]\\[directory-path]");
DefaultFileMonitor fm = new DefaultFileMonitor(new FileListener()
{
#Override
public void fileChanged(final FileChangeEvent fileChangeEvt) throws Exception
{
System.out.println("#" + System.currentTimeMillis() + ": " + fileChangeEvt.getFile().getName() + " changed .." );
}
#Override
public void fileCreated(FileChangeEvent fileChangeEvt) throws Exception
{
System.out.println("#" + System.currentTimeMillis() + ": " + fileChangeEvt.getFile().getName() + " created .." );
}
#Override
public void fileDeleted(FileChangeEvent fileChangeEvt) throws Exception
{
System.out.println("#" + System.currentTimeMillis() + ": " + fileChangeEvt.getFile().getName() + " deleted .." );
}
});
fm.setDelay(5000);
fm.addFile(file);
FileObject[] children = file.getChildren();
for(FileObject child : children)
{
System.out.println(child.getURL());
}
fm.start();
}
}